Ruby on Rails is one of the most popular application stacks for developers wishing to create sites and web apps. The Ruby programming language, coupled with the Rails development framework, makes app development simple.
Since Ruby on Rails doesn’t come in a neatly packaged format, getting the framework installed used to be one of the more difficult parts of getting started. Luckily, tools like rvm, the Ruby Version Manager, have made installation simple.
In this guide, we’ll show how to install rvm
on an Ubuntu 14.04 VPS, and use it to install a stable version of Ruby and Rails. Although you can go through these procedures as the root user, we’ll assume you’re operating using an unprivileged user as shown in steps 1-4 in this guide.
The quickest way of installing Ruby on Rails with rvm
is to run the following commands as a regular user:
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
\curl -sSL https://get.rvm.io | bash -s stable --rails
You will be prompted for your regular user’s password as part of the installation procedure.
Let’s go over exactly what’s happening here.
The gpg
command contacts a public key server and requests a key associated with the given ID. In this case we are requesting the RVM project’s key which is used to sign each RVM release. Having the RVM project’s public key allows us to verify the legitimacy of the RVM release we will be downloading, which is signed with the matching private key.
The \curl
portion uses the curl
web grabbing utility to grab a script file from the rvm
website. The backslash that leads the command ensures that we are using the regular curl
command and not any altered, aliased version.
The -s
flag indicates that the utility should operate in silent mode, the -S
flag overrides some of this to allow curl
to output errors if it fails. The -L
flag tells the utility to follow redirects.
The script is then piped directly to bash
for processing. The -s
flag indicates that the input is coming from standard in. We then specify that we want the latest stable version of rvm
, and that we also want to install the latest stable Rails version, which will pull in the associated Ruby.
Following a long installation procedure, all you need to do is source the rvm
scripts by typing:
source ~/.rvm/scripts/rvm
You should now have a full Ruby on Rails environment configured.
If you need to install specific versions of Ruby for your application, you can do so with rvm
like this:
<pre> rvm install <span class=“highlight”>ruby_version</span> </pre>
After the installation, we can list the available Ruby versions we have installed by typing:
rvm list
We can switch between the Ruby versions by typing:
<pre> rvm use <span class=“highlight”>ruby_version</span> </pre>
We can use various Rails versions with each Ruby by creating gemsets
and then installing Rails within those using the normal gem
commands:
<pre> rvm gemset create <span class=“highlight”>gemset_name</span> # create a gemset rvm <span class=“highlight”>ruby_version</span>@<span class=“highlight”>gemset_name</span> # specify Ruby version and our new gemset gem install rails -v <span class=“highlight”>rails_version</span> # install specific Rails version </pre>
The gemsets allow us to have self-contained environments for gems and allow us to have multiple environments for each version of Ruby that we install.
We have covered the basics of how to install rvm
and Ruby on Rails here, but there is a lot more to learn about rvm
. Check out our article on how to use rvm to manage your Ruby environments to learn more about working with rvm.
<div class=“author”>By Justin Ellingwood</div>
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Thanks works well, but now what? I want to deploy with Capistrano but I cannot figure out how to do it. There is a tutorial though it uses rbenv. Can someone tell me where to find how to deploy with Capistrano and .rvm?
I had to add the key
gpg --keyserver hkp://keys.gnupg.net --recv-keys D39DC0E3
before step 1, as this was a fresh install.
I guess it would be a good idea to include the command to source the rvm scripts in .bashrc
echo “source ~/.rvm/scripts/rvm” >> ~/.bashrc
Thank you very much guys, you save my life! Awesome post, and Pura Vida from Costa Rica :)
Here is some more commands you need to include RVM Installation tutorial
Need to import key for the curl to work:
Source : https://rvm.io/
hello bro…i have got an error while installing ruby…when i execute the following code \curl -sSL https://get.rvm.io | bash -s stable --rails it give me following error
Successfully installed rails-deprecated_sanitizer-1.0.3 ERROR: While executing gem … (Gem::RemoteFetcher::FetchError) bad response Service Unavailable 503 (https://rubygems.global.ssl.fastly.net/quick/Marshal.4.8/mini_portile-0.6.2.gemspec.rz)
please help me what i do
I’ve created a PPA (.deb package + auto updater) for rvm on 14.04.
Install instructions: https://github.com/raelgc/ubuntu_rvm
Great post, thank you!
By the way, I could not find the file “~/.rvm/scripts/rvm”, hence “source ~/.rvm/scripts/rvm” did not work… You need to run “source /usr/local/rvm/scripts/rvm” instead. -tested in Ubuntu 14.04 LTS-
Thanks.
Worked great adding that to the bashrc as dennyac said, you should add it to article. thanks