May 25, 2012

Beginner

How To Install Ruby on Rails on Ubuntu 12.04 LTS (Precise Pangolin) with RVM

Tagged In: Ruby On Rails, Ubuntu, Ruby

About Ruby on Rails


Ruby on Rails is an application stack that provides developers with a framework to quickly create a variety of web applications.

Ruby on Rails does take a little while to install on a virtual server, but luckily there are a lot of helpful tools to make this process as easy as possible.

You can run this tutorial on your droplet as a user with sudo privileges. You can check out how to set that up here: Ubuntu Server Setup

Step One— Install Ruby with RVM


Before we do anything else, we should run a quick update to make sure that all of the packages we download to our VPS are up to date:
sudo apt-get update

Once that's done, we can start installing RVM, Ruby Version Manager. This is a great program that lets you use several versions of Ruby on one server; however, in this case, we will just use it to install the latest version of Ruby on the droplet.

If you do not have curl on your system, you can start by installing it:
sudo apt-get install curl

To install RVM, open terminal and type in this command:
\curl -L https://get.rvm.io | bash -s stable

After it is done installing, load RVM. You may first need to exit out of your shell session and start up a new one.
source ~/.rvm/scripts/rvm

In order to work, RVM has some of its own dependancies that need to be installed. To automatically install them:
rvm requirements

You may need to enter your root password to allow the installation of these dependencies.
On occasion the zlib package may be reported as missing. The RVM page describes the issue and the solution in greater detail here.

Step Two—Install Ruby


Once you are using RVM, installing Ruby is easy.
rvm install ruby

The latest ruby is now installed. However, since we accessed it through a program that has a variety of Ruby versions, we need to tell the system to use the version we just installed by default.
rvm use ruby --default

Step Three—Install RubyGems


The next step makes sure that we have all the required components of Ruby on Rails. We can continue to use RVM to install gems; type this line into terminal.
 rvm rubygems current

Step Four—Install Rails


Once everything is set up, it is time to install Rails.

To start, open terminal and type in:
gem install rails

This process may take a while, be patient with it. Once it finishes you will have Ruby on Rails installed on your droplet.

See More

Once you have installed Ruby on Rails on your server, you can proceed to Create a SSL Certificate for your site or Install an FTP server



By Etel Sverdlov

Share this Tutorial

Vote on Hacker News

Try this tutorial on an SSD cloud server.

Includes 512MB RAM, 20GB SSD Disk, and 1TB Transfer for $5/mo! Learn more

Create an account or login:

60 Comments

Write Tutorial
  • Gravatar daniel almost 2 years

    you might want to sudo apt-get curl *before* you try to run the curl command to fetch the rvm installer. It's in the rvm dependencies, but that's too late.

  • Gravatar Moisey almost 2 years

    Thanks for the feedback, most of the virtual server images we deploy on DigitalOcean have curl pre-installed but we'll update the documentation because that's a great point.

  • Gravatar bri.amesse almost 2 years

    The only problem I had was even though I install all the dependencies I am still missing a libz package so before I do "rvm install 1.9.3" I needed to write "$rvm pkg install zlib" ... because I got this error "ERROR: Loading command: install (LoadError) cannot load such file -- zlib ERROR: While executing gem ... (NameError) uninitialized constant Gem::Commands::InstallCommand" ... I had to rvm remove default and install it again and then I was good :) Thanks for the help!

  • Gravatar Moisey almost 2 years

    We'll add the libz into the requirements, our base OS was most likely a bit different from the get go but its a good thing to watch out for. Thanks.

  • Gravatar Etel over 1 year

    Thank you for catching the issue with zlib. It seems that missing the zlib package is a common problem—it is described in greater detail here: https://rvm.io/packages/zlib/ There's now a link in the tutorial to the page that describes RVM's resolution. Thanks for posting your solution!

  • Gravatar powertoaster over 1 year

    It is really important that you make sure none of the debian ruby or ruby-rvm packages are installed before following these steps. If they were make sure to uninstall them all with the apt-get --purge option. sudo apt-get remove ruby-rvm --purge If you do not do this then the configuration file from the broken version included in the deb package will cause rvm to fail.

  • Gravatar gorrillamcdouglas over 1 year

    Just to let you know, I was going through this tutorial and noticed a typo in one of the commands. In the last command of step 1, you don't need rvm or sudo for that command. It's just installing packages from apt-get.

  • Gravatar Moisey over 1 year

    Hey, For system libraries its best to install them as root and then install RVM under a specific user so that there isn't an overlap with the system ruby binary which a lot of other applications such as puppet may depend on. Thanks

  • Gravatar gorrillamcdouglas over 1 year

    Oh ok, I understand now. I'm just setting up a test server anyways (on the 24-hour trial). When I setup the actual production server, I'll be sure to install rvm under a separate user.

  • Gravatar ololo over 1 year

    thanks

  • Gravatar praamodtiwari over 1 year

    I got the problem by running rvm requirements ___________________________________________ rvmsudo apt-get install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion _____________________________________________________________________________________ something like this: Reading package lists... Done Building dependency tree Reading state information... Done Note, selecting 'libxslt1-dev' instead of 'libxslt-dev' Note, selecting 'libncurses5-dev' instead of 'ncurses-dev' autoconf is already the newest version. automake is already the newest version. bison is already the newest version. build-essential is already the newest version. curl is already the newest version. git-core is already the newest version. libc6-dev is already the newest version. libncurses5-dev is already the newest version. libreadline6 is already the newest version. libreadline6-dev is already the newest version. libsqlite3-dev is already the newest version. libtool is already the newest version. libyaml-dev is already the newest version. pkg-config is already the newest version. sqlite3 is already the newest version. subversion is already the newest version. zlib1g is already the newest version. zlib1g-dev is already the newest version. openssl is already the newest version. Some packages could not be installed. This may mean that you have requested an impossible situation or if you are using the unstable distribution that some required packages have not yet been created or been moved out of Incoming. The following information may help to resolve the situation: The following packages have unmet dependencies: libssl-dev : Depends: libssl1.0.0 (= 1.0.1-4ubuntu3) but 1.0.1-4ubuntu5.2 is to be installed Recommends: libssl-doc but it is not going to be installed libxml2-dev : Depends: libxml2 (= 2.7.8.dfsg-5.1ubuntu4) but 2.7.8.dfsg-5.1ubuntu4.1 is to be installed E: Unable to correct problems, you have held broken packages. ___________________________________________________________________________________________ What i do to fix it??

  • Gravatar Jeff Carr over 1 year

    I would try: apt-get update apt-get upgrade to fix the dependency problems. Beyond that, if you still have problems and are running your virtual machine on digital ocean, you can open up a ticket with us. -- Jeff

  • Gravatar eugene.liskovets over 1 year

    Hi, I would like to let everyone know that you need to install nodejs for running your first ruby application. So, for creating application you need to run next commands: sudo apt-get install nodejs rails new app_name cd app_name rails server Your first ruby application now available by the url http://localhost:300

  • Gravatar eugene.liskovets over 1 year

    Sorry, but it looks like I have some mistake in my previous message and can't edit that. Your application will available by http://localhost:3000/

  • Gravatar poppopopo over 1 year

    why do you need nodejs to run ruby apps??

  • Gravatar Moisey over 1 year

    With Rails 3.1 and the introduction of asset pipelines which compile your CSS and JS code execJS is a requirement for the default installation of Rails. If you comment everything out of your Gemfile related to assets then execJS isn't required. NodeJS provides execJS and is supported via apt-get install so it's just an easy way to get execJS installed.

  • Gravatar dguilford about 1 year

    This appears to have worked great. Thanks so much!

  • Gravatar mdahmann about 1 year

    For me it was "source /usr/local/rvm/src/rvm/scripts/rvm" instead of "source ~/.rvm/scripts/rvm". That path is found using locate rvm command

  • Gravatar alanwilhelm about 1 year

    Is this article suggesting that people run a ruby app on DO using the built in Webrick server which is only meant to streamline development. Please have a look at Nginx/Phusion or Possibly Nginx in as a reverse proxy to Unicorn.

  • Gravatar dan_paul about 1 year

    I needed to add the autolibs=enabled argument when installing rvm in order to run the rvm requirements command: curl -L get.rvm.io | bash -s stable --autolibs=enabled

  • Gravatar webdevotion 11 months

    I had to set some env variables to be able to install Rubygems on Ubuntu 13.04 x64 ( clean install ). https://github.com/wayneeseguin/rvm/issues/1689#issuecomment-19076736

  • Gravatar Svilen Gospodinov 10 months

    You can just do \curl -L https://get.rvm.io | bash -s stable --rails

  • Gravatar gagan.remba 9 months

    I am new user of Ubuntu and I found these steps worked for me. But problem is that whenever I restart my computer I have to follow these steps again and again. How can i fix this issue ?

  • Gravatar Kamal Nasser 9 months

    @gagan.remba How come you need to follow these steps every time you reboot your computer? Do you get any errors if you don't do that when you reboot?

  • Gravatar gagan.remba 9 months

    I get this error - The program 'rails' can be found in the following packages: * rails * ruby-railties-3.2 Try: sudo apt-get install

  • Gravatar Kamal Nasser 9 months

    @gagan.remba: Did you run 'gem install rails'? You also need to run "source ~/.rvm/scripts/rvm" or add it to .bashrc or .zshrc.

  • Gravatar robert.vansant 9 months

    so i ran through this tutorial and it appears the '~/.rvm/scripts/rvm' isn't referenced in my root folder, but actually it's located here '/usr/local/rvm/scripts/rvm', so i got rvm to run by doing this: "echo '[[ -s "/usr/local/rvm/scripts/rvm" ]] && source "/usr/local/rvm/scripts/rvm"' >> ~/.bashrc" then "source ~/.bashrc" and added this to my bash commands. i hope this helps anyone who had similar problems.

  • Gravatar Kamal Nasser 9 months

    @robert.vansant: It depends on the user you install rvm as. Installing it as root places it in /usr/local/rvm while installing it as a regular user places it in ~/.rvm.

  • Gravatar roland 9 months

    Great! At last I could get the latest Redmine running on Ubuntu. The provided packages for ruby (or something) have been consistently broken, but now I have Redmine running. You might want to add to the start of the document that one can install this all system-wide by doing "sudo su - " before starting. Installing everything into a user home directory on a server doesn't help much :-)

  • Gravatar alejandragomezmendoza 8 months

    hi i got a problem with the step two: when i am trying to install ruby pops up a warning "Failed to create the file ruby-1.9.3-p448.tar.bz2" and error (23) Failed writing body (0 != 1167) There was an error(23). Failed download There has been an error fetching the ruby interpreter. Halting the installation. so I want to know why and what can i do

  • Gravatar Kamal Nasser 8 months

    @alejandragomezmendoza: Is there enough space on your droplet?

    df -h

  • Gravatar contactmayankjain 8 months

    For rvn It should be source /etc/profile.d/rvm.sh

  • Gravatar contactmayankjain 8 months

    I am getting error while installing rails # gem install rails Fetching: i18n-0.6.5.gem (100%) Successfully installed i18n-0.6.5 Fetching: multi_json-1.7.9.gem (100%) Successfully installed multi_json-1.7.9 Fetching: tzinfo-0.3.37.gem (100%) Successfully installed tzinfo-0.3.37 Fetching: minitest-4.7.5.gem (100%) Successfully installed minitest-4.7.5 Fetching: atomic-1.1.13.gem (100%) Building native extensions. This could take a while... ERROR: Error installing rails: ERROR: Failed to build gem native extension. /usr/local/rvm/rubies/ruby-1.9.3-p448/bin/ruby extconf.rb Gem files will remain installed in /usr/local/rvm/gems/ruby-1.9.3-p448/gems/atomic-1.1.13 for inspection. Results logged to /usr/local/rvm/gems/ruby-1.9.3-p448/gems/atomic-1.1.13/ext/gem_make.out

  • Gravatar naga2raja 8 months

    Great Work!! It really helped me to understand as a beginner

  • Gravatar Kamal Nasser 8 months

    @contactmayankjain: It depends, so if you installed it as root the path will be different from the path it would get installed in if you're not installing it as root.

    rvm install 1.9.3-dev
    should fix it

  • Gravatar karinjramos13 8 months

    New Digital Ocean customer here. Need some rvm help. This is what I've done so far: - 1-Click Install Ruby on Rails on Ubuntu 12.10. - Initial Server Setup with Ubuntu 12.04. From my home directory /home/me I type rvm install 2.0.0 and get this error: mkdir: cannot create directory `/usr/local/rvm/log/ruby-2.0.0-p195': Permission denied Could not detect ruby version/name for installation, please be more specific. I tried rvmsudo install 2.0.0 and get this error: Warning: can not check `/etc/sudoers` for `secure_path`, falling back to call via `/usr/bin/env`, this breaks rules from `/etc/sudoers`. Run: export rvmsudo_secure_path=1 to avoid the warning, put it in shell initialization file to make it persistent. In case there is no `secure_path` in `/etc/sudoers`. Run: export rvmsudo_secure_path=0 to avoid the warning, put it in shell initialization file to make it persistent. [sudo] password for ltrainpr: install: missing destination file operand after `2.0.0' Try `install --help' for more information. What am I missing? rvm file is under usr/local/rvm

  • Gravatar Kamal Nasser 8 months

    @karinjramos13: The 1-click ruby on rails image is already set up for you, take a look at this article: https://www.digitalocean.com/community/articles/how-to-1-click-install-ruby-on-rails-on-ubuntu-12-10-with-digitalocean

  • Gravatar karinjramos13 8 months

    I've re-read the article. I tried the command: rvm use ruby 2.0.0-p195 --default and got this error: mkdir: cannot create directory `/usr/local/rvm/log/ruby-2.0.0-p195': Permission denied Tried rvmsudo use ruby 2.0.0-p195 --default and got this error: /usr/bin/env: use: No such file or directory When I do rvm list, I get: rvm rubies =* ruby-1.9.3-p429 [ x86_64 ] # => - current # =* - current && default # * - default I would like to use ruby 2.0.0 with rvm. What do I need to do?

  • Gravatar Kamal Nasser 8 months

    @karinjramos13: Did you run

    rvm install ruby-2.0.0-p195
    first?

  • Gravatar karinjramos13 8 months

    Yes. Just ran it again, with the same result: mkdir: cannot create directory `/usr/local/rvm/log/ruby-2.0.0-p195': Permission denied Could not detect ruby version/name for installation, please be more specific. When I try it with rvmsudo I get: Warning: can not check `/etc/sudoers` for `secure_path`, falling back to call via `/usr/bin/env`, this breaks rules from `/etc/sudoers`. Run: export rvmsudo_secure_path=1 to avoid the warning, put it in shell initialization file to make it persistent. In case there is no `secure_path` in `/etc/sudoers`. Run: export rvmsudo_secure_path=0 to avoid the warning, put it in shell initialization file to make it persistent. [sudo] password for ltrainpr: install: missing destination file operand after `ruby-2.0.0-p195' Try `install --help' for more information.

  • Gravatar Kamal Nasser 8 months

    @karinjramos13: Try running it through "sudo" instead -- does it work?

  • Gravatar karinjramos13 8 months

    When I run sudo I get: sudo: rvm: command not found

  • Gravatar Kamal Nasser 8 months

    @karinjramos13: -> https://www.digitalocean.com/community/questions/rvm-is-not-working

  • Gravatar karinjramos13 8 months

    Hi Kamal. Need some more help. Posted more info on: https://www.digitalocean.com/community/questions/rvm-is-not-working

  • Gravatar ajinkyab1987 5 months

    hey thanks man i tried this on my Ubuntu 13.04. working fine. I needed Ruby for my SASS :)

  • Gravatar spocks_penis 4 months

    I have a ruby installation on another Ubuntu 12.04 that was very laborious - and fraught with errors - for my production Foundation 4 workstation. Wanting to try Foundation 5 - and not wanting to mess up a production workstation - I figured I'd try to install ruby and Foundation 5 on a fresh 12.04 installation. What resulted was this: gem install rails ERROR: Could not find a valid gem 'rails' (>= 0), here is why: Unable to download data from https://rubygems.org/ - Errno::ECONNREFUSED: Connection refused - connect(2) (https://rubygems.org/latest_specs.4.8.gz) It has been my experience that gems aren't really happy campers on Ubuntu. Without a doubt.

  • Gravatar sushil 4 months

    while i am trying to command sudo gem install rails its giving me an error,help please ERROR: While generating documentation for rails-4.0.2 ... MESSAGE: error generating /var/lib/gems/1.9.1/doc/rails-4.0.2/rdoc/guides/Rakefile.html: Error while evaluating /var/lib/gems/1.9.1/gems/rdoc-3.12.2/lib/rdoc/generator/template/darkfish/page.rhtml: undefined method `chomp' for nil:NilClass (RDoc::Error) ... RDOC args: --op /var/lib/gems/1.9.1/doc/rails-4.0.2/rdoc lib --title rails-4.0.2 Documentation --quiet

  • Gravatar dwpbr2013 4 months

    I just read the for Ubuntu 13.x is recommended using this: \curl -L https://get.rvm.io | bash -s stable --ruby Instead of the above \curl command.

  • Gravatar dananourie 3 months

    I get the right version of rails and ruby when I'm in any directory except for the /home/rails. I think I did something to mess it up. I've tried reinstalling rails, updating the gems, etc. And when I ask for the rails -v I get this: Could not find gem 'rails (= 4.0.0) ruby' in the gems available on this machine. Run `bundle install` to install missing gems. I've run bundle install. And still keep getting this problem. I had copied my app files over the ones in the rail dir via sftp, and I'm wondering if I hosed a config file? It was working until I copied in my files. If I create a new project under home, such as home/virtuallibrary, will unicorn still be able to run it?

  • Gravatar dananourie 3 months

    Nevermind. I just fixed it. Rebooted, then tried again. That did the magic.

  • Gravatar tauhidul35 3 months

    All commands run successfully except last one. When I run "gem install rails" it shows an error given below - ERROR: While executing gem ... (NoMethodError) undefined method `ord' for nil:NilClass

  • Gravatar Kamal Nasser 3 months

    @tauhidul35: I don't have much experience with ruby, check out http://stackoverflow.com/questions/21097255/error-when-run-gem-install-rails—it's not solved it, but I'm sure the folks at StackOverflow are able to help you.

  • Gravatar jonjdepp 3 months

    i jst now downloaded, i goto work it out n comment soon :-)

  • Gravatar danieldristic 3 months

    You might want to replace the final command by "gem install rails --no-ri --no-rdoc" as most people don't use the local docs and it saves a few minutes of installation.

  • Gravatar cfair 2 months

    Basically the mac instructions for installing rails works just fine on Linux.

  • Gravatar Mario Andrés Corrrea Abendaño about 1 month

    Awesome, thanks!

  • Gravatar s_cheen about 1 month

    I tried "gem install rails" and got ERROR: While executing gem ... (Errno::EACCES) Permission denied - /var/lib/gems What's the problem?

  • Gravatar alexander.ververis about 1 month

    RE node.js installation (RoR wants it installed) I really like this snippet: sudo apt-add-repository ppa:chris-lea/node.js && sudo apt-get update && sudo apt-get install nodejs if that first command fails you need to install python-software-properties like so: sudo apt-get install python-software-properties This is probably the best way to get node running on Ubuntu.

  • Gravatar jaskaranrajal 21 days

    I want to install RVM in ubuntu and i am folling these steps root@jaskaran-Vostro-1550:/home/user_name# sudo apt-get install curl done this successfully root@jaskaran-Vostro-1550:/home/user_name# curl -L https://get.rvm.io | bash -s stable done this successfully but when i run this command root@jaskaran-Vostro-1550:/home/user_name# source ~/.rvm/scripts/rvm result like that bash: /root/.rvm/scripts/rvm: No such file or directory what wrong in this

  • Gravatar jacindaz 4 days

    I'm having trouble on the "rvm rubygems current" step. I get the error below. Any idea what might be happening? Thank you so much! system - #downloading rubygems-2.2.2 system - #extracting rubygems-2.2.2.... system - #removing old rubygems......... system - #installing rubygems-2.2.2. Error running 'env GEM_HOME= GEM_PATH= /home/jacinda/.rvm/rubies/system/bin/ruby -d /home/jacinda/.rvm/src/rubygems-2.2.2/setup.rb', showing last 15 lines of /home/jacinda/.rvm/log/1397681932_system/rubygems.install.log [2014-04-16 16:58:52] /home/jacinda/.rvm/rubies/system/bin/ruby current path: /home/jacinda/.rvm/src/rubygems-2.2.2 PATH=/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/jacinda/.rvm/bin command(6): env GEM_HOME= GEM_PATH= /home/jacinda/.rvm/rubies/system/bin/ruby -d /home/jacinda/.rvm/src/rubygems-2.2.2/setup.rb env: /home/jacinda/.rvm/rubies/system/bin/ruby: No such file or directory

Leave a Comment

Create an account or login:
Ajax-loader