Installing Rails

suggest change

Installing Rails on Ubuntu

On a clean Ubuntu, installing Rails is straightforward.

Upgrading ubuntu packages

sudo apt-get update
sudo apt-get upgrade

Install Ruby and Rails dependencies

sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev

Install a Ruby version manager. This guide uses rbenv.

git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc

Installing Ruby Build

git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc

Restart Shell

exec $SHELL

Install Ruby

rbenv install 2.3.1
rbenv global 2.3.1
rbenv rehash

Install Rails. Ruby 2.3 cannot install current Rails. Pin a 5.0 release, which matches this Ruby:

gem install rails -v '~> 5.0.0'

Installing Rails on Windows

Step 1: Installing Ruby

Install Ruby first. RubyInstaller is a precompiled build for Windows. The DevKit steps below match the older RubyInstaller. Current RubyInstaller includes MSYS2, so ruby dk.rb does not apply to that installer.

Step 2: Ruby Development Kit

After installing Ruby, we can try to install Rails. But some of the libraries Rails depends on need some build tools in order to be compiled, and Windows lacks those tools by default. You can identify this if you see an error while attempting to install Rails Gem::InstallError: The ‘[gem name]’ native gem requires installed build tools. To fix this, we need to install the Ruby Development Kit.

Now we need to make the DevKit tools available to Ruby.

The DevKit should now be available for your Ruby tools to use when installing new libraries.

Step 3: Rails

Now we can install Rails. Rails comes as a Ruby gem. In your command prompt, type:

gem install rails

gem downloads Rails and the gems it depends on. With no version, it installs the newest Rails, which may not match the Ruby you just installed. Pin a release the same way as on Ubuntu.

Step 4: Node.js

Some libraries that Rails depends on require a JavaScript runtime to be installed. Let’s install Node.js so that those libraries work properly.

Once your computer restarts, don’t forget to go to the Windows menu, click “All Programs”, scroll down to Ruby, and click “Start Command Prompt with Ruby”.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents