I have some conflicts of ruby version.
When I run ruby -v in my terminal (in osx), I get the 1.8.7 version. I tried to upgrade ruby version, installing rvm, with this command curl -L https://get.rvm.io | bash -s stable --autolibs=3 --rails. Then I tried to run rvm install ruby-1.9.3-p362, and I was told that rvm was not a found command. So I ran source /Users/host/.rvm/scripts/rvm install ruby-1.9.3-p362, this worked and when I run in my bash ruby -v, I get ruby 2.0.0. But it seems to be related to my current terminal session since when I run ruby -v in another session, I always get 1.8.7 version. How can I set on my .bash_profile (or elswhere) the right version of ruby (and of rails) ?
RVM allows to install multiple versions of ruby on a single *nix box. Each ruby version is kinda sandboxed from another one. For the first time, you will need to specify a default version of ruby. This will be needed only for the first time.
rvm use 1.9.3-p290 --default
To switch to another version, simply type:
rvm use 1.9.2
Rails is just a gem. To get the most out of RVM, create a gemset and install all gems for one ruby version within one gemset. i.e. one gemset per ruby version.
This works like :
rvm gemset create my_gem_set
Gemset 'my_gem_set' created.
rvm gemset use my_gem_set
You can also use .rvmrc file in your project directory to 'load' just the required gems for your app. There is one .rvmrc per project. You can refer rvm.io for docs on rvmrc
You should set the default ruby via rvm: https://rvm.io/rubies/default/
rvm --default use <ruby_version>
You need to enable login shell in your terminal emulator, here is example how to set it up in gnome-terminal https://rvm.io/integration/gnome-terminal/
Related
How do I safely upgrade my ruby on rails app to use a new ruby version, using rvm?
Suppose your app is my_app and you are using ruby version a.b.c and want to go to ruby version x.y.z.
Step 0
Before starting, make sure you have the up to date version of rvm
rvm get stable
rvm reload
Step 1
First if you do not have a gemset for your current ruby version create one and make it the default. This gives you an easy way to go back if your upgrade breaks your tests. If you do not want to do this, go to step 2.
rvm gemset create my_app_abc
The switch to that gemset and install the gems into that gemset, and make it the default gemset for the directory
rvm a.b.c#my_app_abc
bundle
rvm --ruby-version use a.b.c#my_app_abc
Step 2
Now upgrade to the new ruby version and create a gemset for it.
rvm install x.y.z
rvm use x.y.z
rvm gemset create my_app_xyz
rvm x.y.z#my_app_xyz
It is considered best practice to specify the ruby version in your Gemfile so
make sure you have ruby 'x.y.z' at the top of your Gemfile. Then
gem install bundle
bundle
This is where the fun can start, you may get errors at this point and use a combination of following the error instructions or googling for help, etc to solve them. When you can bundle successfully, then run all your tests.
When your tests have all passed, then you have successfuly upgraded. If you get stuck, you can go back to your old installation, using rvm a.b.c#my_app_abc.
Once you are happy with your new installation then do
rvm --ruby-version use x.y.z#my_app_xyz
to make this the default setup for this app. This means when you change into this app from other projects, it will automatically load ruby version x.y.z and the corresponding gemset.
According to this blog, if you always precede commands by bundle exec you do not need to use gemsets. In that case, you would simply do
rvm --ruby-version use x.y.z
I'm running Ubuntu 12.04 LTS, and installed Ruby via RVM.
The problem is, when I type ruby -v into the terminal, it says that my Ruby version is 1.8.7, and using the shotgun gem for Sinatra also says that I'm running Ruby 1.8.7.
But when I type rvm list it shows that the only version of Ruby that I have installed is 2.0.0 and it is my current and default version.
I installed Ruby 2.0.0 via RVM and it is the only version I had installed on my machine.
Now when I tried to install Rails 4 but got an error saying that I need Ruby 1.9 or higher.
How do I know what version am I really on, and how do I set 2.0.0 as my only version?
On your terminal, try running:
which -a ruby
This will output all the installed Ruby versions (via RVM, or otherwise) on your system in your PATH. If 1.8.7 is your system Ruby version, you can uninstall the system Ruby using:
sudo apt-get purge ruby
Once you have made sure you have Ruby installed via RVM alone, in your login shell you can type:
rvm --default use 2.0.0
You don't need to do this if you have only one Ruby version installed.
If you still face issues with any system Ruby files, try running:
dpkg-query -l '*ruby*'
This will output a bunch of Ruby-related files and packages which are, or were, installed on your system at the system level. Check the status of each to find if any of them is native and is causing issues.
Run this command:
rvm get stable --auto-dotfiles
and make sure to read all the output. RVM will tell you if something is wrong, which in your case might be because GEM_HOME is set to something different then PATH.
The ruby version 1.8.7 seems to be your system ruby.
Normally you can choose the ruby version you'd like, if you are using rvm with following. Simple change into your directory in a new terminal and type in:
rvm use 2.0.0
You can find more details about rvm here: http://rvm.io
Open the website and scroll down, you will see a few helpful links. "Setting up default rubies" for example could help you.
Update:
To set the ruby as default:
rvm use 2.0.0 --default
If you have access to a console in the context you are investigating, you can determine which version you are running by printing the value of the global constant RUBY_VERSION.
Accidently I have installed both versions of ruby on my system and now the default version is set to
$ ruby -v
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
but I need to set the default version to 2.0.0...
for this I used the command
$ rvm 2.0.0p294 --default
but it says rvm is not currently installed though I installed it, typing various commands(via google) .
Also I want to install an Integrated Ruby shell in ubuntu 13.04, do suggest how to do it.
I have also installed Aptana Studio on my system, now how should I get started with it.
Finally, the last problem is tell me how to check whether rails is currently installed in my system or not...
Thanx in advance!!
to use a gemset try writing
rvm use ruby_gemset_version
to check the rails version try to type rails -v
you have to install RVM (ruby version manager), then you have control to use any specific versions of ruby, and coming to rails you have to manually install rails gem once you have installed rvm and selected a version.
This would be helpful to install rvm
https://rvm.io/rvm/install
After installation you have to install ruby versions.
Then you can use the following cmd
$ rvm use 2.0.0
to use ruby 2.0.0
Thank you.
Go to this http://rvm.io/rvm/install It has instruction to install and cofigure RVM. It is dependant on CURL lib. So make sure you have curl installed in your system, if not then the command is
#sudo apt-get install curl
Once it is intalled and configured properly.
On Ubuntu:
GoTo Terminal > Profile Preferences > Title and Command > Set checkbox for (Run command as login shell)
Install rubies using rvm install.
I am trying to install Rails into a new rvm gemset.
I tried the following:
rvm gemset create rails-4.0
output: gemset created rails-4.0
Next I did:
rvm 2.0.0#rails-4.0
rvm gemset list:
gemsets for ruby-2.0.0-p0 (found in /Users/me/.rvm/gems/ruby-2.0.0-p0)
(default)
global
=> rails-4.0
rails -v
Rails is not currently installed on this system. To get the latest
version, simply type:
$ sudo gem install rails
Do the rvm commands I listed not install rails 4.0?
This command:
rvm gemset create rails-4.0
is creating basically a directory structure to hold the gems. You could have just as easily called it something other than "rails-4.0" like "foo" and it would be the same behavior.
This command:
rvm 2.0.0#rails-4.0
Switches to Ruby 2.0.0 and tells it to use the new gemset named rails-4.0. Again, that could be "foo" or whatever you called it.
Now, to get Rails 4.0.x, you'd do:
gem install rails --version=4.0
As Barrett pointed out earlier, to get a pre/beta/rc release, you can specify the whole version string, e.g. gem install rails --version=4.0.0.rc2.
Don't sudo, because you shouldn't sudo with rvm, even though it tells you to. With the "system ruby" (ruby not installed by rvm), it may be installed as root, so you need superuser (su) access (superuser do or "sudo") to do that. But, rvm has you install things as the current user, therefore you don't need to sudo.
In addition to the usage tips above, if you don't specify the gem version you won't get the beta or pre version, so to get rails 4, you need:
gem install rails --version=4.0.0.rc1
Maybe try InstallRails?
http://installrails.com/ is a guide for installing rails that deals with these issues for various Operating Systems and setups. It might prove helpful for something like this.
Other answers shows instructions for creating the gemset using default ruby version.
For creating a gemset and use it with different ruby version please follow the instructions below:
Let's say on my machine I have following ruby versions installed and 2.2.0 is the default.
=*ruby-2.2.0 [ x86_64 ]
ruby-2.2.1 [ x86_64 ]
ruby-2.2.3 [ x86_64 ]
Now I have forked a repository from Github and want to test out the repo's code with Rails 5 (edge version) and Ruby 2.2.3 (the latest stable version at the time of this writing). And I prefer using gemsets so I ran following commands:
rvm use 2.2.3#forked-repo --create
That's actually a shortcut for
rvm 2.2.3
rvm gemset create forked-repo
Next I would run following command to install bundler:
forked_repo_root$ gem install bundler
forked_repo_root$ bundle
That should install the gems used in your forked-repo in the gemset created above.
Reference: https://rvm.io/gemsets/creating
I have been using rvm and when I installed ruby 1.9.2, it installed ruby-1.9.2-p290 and a few days back I wasn't able to reference the older one but it asked to install ruby-1.9.2-p318.
Is it mandatory to move to the newer version or would it be possible for us to instruct rvm to use the gemset created with the older version.
What brandon said is correct also you may want to set up a default ruby version with the --default flag. This will ensure that you are using the same version every time when you start up your terminal.
rvm use ruby-1.9.2-p290 --default
You may also want to set up a .rvmrc file in the directory you are working in to ensure that other developers are using the same ruby version and patch level as you are.
touch .rvmrc && echo "rvm use ruby-1.9.2-p290" >> .rvmrc
All the RVM commands, such as rvm install and rvm use, can take a patchlevel, e.g.: rvm install ruby-1.9.2-p290. If you don't specify one, the latest available patchlevel will be used.