This tutorial is out of date and no longer maintained.
This article covers a version of Ubuntu that is no longer supported. If you are currently operate a server running Ubuntu 12.04, we highly recommend upgrading or migrating to a supported version of Ubuntu:
Reason: Ubuntu 12.04 reached end of life (EOL) on April 28, 2017 and no longer receives security patches or updates. This guide is no longer maintained.
See Instead:
This guide might still be useful as a reference, but may not work on other Ubuntu releases. If available, we strongly recommend using a guide written for the version of Ubuntu you are using. You can use the search functionality at the top of the page to find a more recent version.
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
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.
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
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
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.
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
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!
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.
This comment has been deleted
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.
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!
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.
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!
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.
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.
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
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.
thanks
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??
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
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
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/
why do you need nodejs to run ruby apps??
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.
This appears to have worked great. Thanks so much!
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
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.
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
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
You can just do
\curl -L https://get.rvm.io | bash -s stable --rails
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 ?
@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?
I get this error - The program ‘rails’ can be found in the following packages: * rails * ruby-railties-3.2 Try: sudo apt-get install <selected package>
@gagan.remba: Did you run ‘gem install rails’? You also need to run “source ~/.rvm/scripts/rvm” or add it to .bashrc or .zshrc.
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.
@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.
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 :-)
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