I've installed old Ruby version (specifically, 2.2.3) using RVM and I need to have tab completion on it. I successfully installed tab completion on the current Ruby version, using require "irb/completion" in .irbrc file, and it works.
However, when I switch to 2.2.3 using RVM, I don't have tab completion. Attempt to locate .irbrc file in 2.2.3-version doesn't work, nothing changes. So how to enable it when I switch to old version?
Related
This question seems to happen a lot (here, here, and here), but never with a successful answer.
I have ruby 2.5.0 installed correctly and have verified it with ruby -v. However, when I open a new Terminal tab, it defaults me back to ruby 2.3.3p222 for some reason. I have ruby '~> 2.5.0' in my gemfile, if it helps.
Does anyone know how this is happening?
RVM can read the .ruby-version file on the root of your project folder.
echo 2.5.0 > .ruby-version
Open a new terminal and check the Ruby version.
A new tab opens a new shell, which re-reads your shell's initialization files. It doesn't start with the environment variables which happen to be set in the currently-active tab.
If you are using rbenv, you can set your global ruby by:
rbenv global 2.5.0
Pretty much the same thing for rvm:
rvm --default use 2.5.0
I use rbenv but other team members use RVM.
When specifying the ruby 2.x.x version in the Gemfile I’ve been doing this:
ruby ENV['RBENV_VERSION'] || '2.2.4'
which grabs the current version I’m using from rbenv and uses it for the Gemfile. However, in production, it is not present and uses the specified version after ||.
I’ve been searching for a similar way to do this in RVM, the ultimate goal being to set up a Gemfile where all developers can use their local version of Ruby and a concrete version is specified for production.
This would allow developers to use rbenv or RVM for a project as well as not need to install new versions of Ruby every time they work on a project with a version they don’t have installed.
Are there any RVM users that can give me an equivalent to ENV['RBENV_VERSION'] for RVM? I’ve been searching a lot and haven’t found anything I like.
The best answer I can see is having RVM users specify the version via an environment variable name agreed upon by the team and used like "Specifying a Ruby version via the environment" as well and use that instead in the Gemfile.
To get the current Ruby version from any RVM instance, you can query it using this method:
rvm list default string | sed s/ruby-//
You can also use the RVM prompt tools to query the current version
rvm-prompt i v | sed s/ruby-//
or
rvm-prompt i v p g | sed s/ruby-//
depending on how detailed you want to allow. Docs for the rvm-prompt command can be found in "rvm-prompt".
If the user chooses to leave RVM at its default version, you get that version reported, but if the Ruby version has been changed in RVM, you get the currently chosen version.
You can chain this in any way that ENV['RBENV_VERSION'] is used, such as:
`rvm list default string | sed s/ruby-//` || 2.2.4
This will choose the current RVM Ruby version or 2.2.4 if RVM doesn't show a version.
Note that RVM has to exist (or at least something called rvm has to be available as an executable). If not, an additional script wrapper may be needed to handle the situation in which it doesn't exist and degrade gracefully.
Personally, I love having it available everywhere, including production environments. It's the very first thing that I install on a new OS instance, even before the text editor, and the second thing that I do is install the appropriate Ruby version with RVM.
I cloned a project and it had a .ruby-version file to specify ruby version of the project. content:
2.0.0
when I switched into the project dir for the first time it gave me warning:
ruby-2.0.0-p645 is not installed. To install do: 'rvm install
ruby-2.0.0-p645'
However it's true that my system didn't have Ruby 2.0 but Ruby 2.2 instead. Does that warning makes sense? Is there a way I use duplicate functionality of (~>) gem dependency in ruby-version file?
Based on the warning, you are using rvm. As another answer says, rbenv can also use a .ruby-version file, but switching to rbenv isn't neccesary, and won't really change anything.
I don't think rvm's .ruby-version file supports a range of versions. It needs to specify a version name that could be passed to rvm use, and I don't think there's any way to say a range of versions there.
You can:
Install ruby 2.0.0 with rvm: rvm install 2.0.0. When you switch into the project directory, rvm will automatically switch you to using ruby 2.0.0 like the .ruby-version file directs.
Simply change your .ruby-version file to specify the version of ruby you want to use instead. Just edit it in a text editor, or run rvm --ruby-version use 2.2.3 to have it write the .ruby-version file for you. Now when you switch into the project directory, rvm will automatically switch you to 2.2.3.
Delete the .ruby-version file entirely. You aren't required to use it. Personally, I don't use them and don't find them helpful. The .ruby-version file is meant to force a particular version of ruby to be used in that project -- but most projects work with multiple versions of ruby, and this isn't really neccesary, and as you've seen can be a headache when it's out of date and is trying to force you to use an older version of ruby, when a newer one would probably work fine.
.ruby_version is used for rbenv
You should install rbenv
or create .rvmrc for rvm
I have multiple Rails apps from 3.2.14 to 3.2.18 in my development environment. I'm using Ruby 1.9.3 (yes, I know) for these apps and it's installed and managed via rbenv. I'm about to build a couple of new apps with Rails 4.1 and Ruby 2.1. My question is, what is the best way to handle installing multiple versions of Ruby using rbenv. Currently 1.9.3 is set to global, but I want different Rails apps (4.1) to use Ruby 2.1.
I guess I'm a bit behind the curve with Ruby management so I could use a hand here. Again, looking to have multiple Rails apps (different versions 3.2.14-4.1.x) and multiple Ruby instances to support each app.
I appreciate the help in advance.
Create a .ruby-version file in your application root directory and specify the ruby version you want. For instance, if you want one application to use 1.9.3 and the other 2.1.0, you'll have a .ruby-version file each in those two applications, specifying the version:
/application1/.ruby-version
1.9.3
/application2/.ruby-version
2.1.0
Update
For every installed version of ruby, you'll have a shims directory which will house all your gems for that particular version. When you switch between ruby versions, rbenv will simply set the environment variables to the one you select.
In the example above, I set the local ruby version for the directory ruby_cookbook to 2.1.2 and a gem list will only show gems installed for 2.1.2.
I also created a .ruby-version with ruby version 1.9.3-p547 in my try_stuff directory. As you can see, gem list only shows gems installed for 1.9.3.
The gems you install are specific to the current version of ruby.
If your project root has a .ruby-version file, your environment will automatically set the current ruby version to the one specified. So, yes, your production environment will need the version you mention in your .ruby-version. If you use git for source control, you can add that file to your .git-ignore and you won't see it in your prod version.
I'm running os x lion. A version of ruby was installed when I installed the OS. I then installed RVM and then installed ruby 1.9.2 and made it the default for new shells.
Default Ruby (for new shells)
ruby-1.9.2-p290 [ x86_64 ]
What happend to the older version of Ruby that was already on my system and how can I remove it since RVM doesn't see it?
When I try to use the new hash syntax in code written in textmate or sublime text 2 it fails. When the same code is run in the shell it works. So how do I make ruby 1.9.2 the only ruby installed on my system?
You do NOT want to uninstall the system Ruby. It is required for a lot of applications (including RVM) to function properly.
If you want applications like Textmate or Sublime Text to use a different version of Ruby, you can update their individual configuration settings to set the path to the Ruby binary you wish to use.
Since those apps don't run ruby from the shell like you do they don't work seamlessly with RVM. Fortunately RVM's web site has instructions on integrating RVM with TextMate. You shouldn't have trouble applying the same process for Sublime Text 2 but if you do the web does not want for tutorials on the topic.
Also, RVM is not responsible for any ruby it didn't install. the only other ruby it gives access to is the system ruby, and there it doesn't do gemsets etc. (This is also due to systems like debian that specifically block off things like gem update --system so you don't poison the package that was installed. RVM protects from that as well)