Install Ruby on Rails using rbenv on a 1&1 Linux Cloud Server

Table of Contents

Introduction

Learn how to install Ruby on Rails on a 1&1 Linux Cloud Server. Ruby on Rails is a framework for writing website applications with Ruby. Ruby on Rails is a server-side web application development platform which combines the Ruby programming language with HTML, CSS, and Javascript. It is a fast, powerful, popular way to design and deploy web applications.

rbenv offers an easy way to install Ruby versions and gems, and is a simple way to manage your Ruby installation.

Requirements

  • A 1&1 Cloud Server running Linux, either Ubuntu 16.04 or CentOS 7.
  • A web server (such as Apache or NGINX) installed and running.

Note: You will need to be logged in as root in order to perform the steps in this tutorial. Always exercise extreme caution while working as root on the command line. It is very easy to delete critical files by accident, which can cripple or destroy your server.

Install rbenv

The first step is to install rbenv, which we will then use to install Ruby and Ruby on Rails. Rbenv handles the installation and management of multiple Ruby environments.

CentOS 7

First, install the dependencies as root:

yum install -y sqlite-devel  zlib zlib-devel gcc-c++ bison patch readline readline-devel autoconf git-core libyaml-devel libffi-devel openssl-devel automake make bzip2 libtool curl 

For the next step, you will need to be logged in as the user who will be using Ruby.

For example, if you are installing this for yourself and your normal (non-root) SSH login is jdoe you would switch to the jdoe user account with the command:

su - jdoe

Switch to this user's home directory with the command:

cd

Install rbenv and update the environment variables with the commands:

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

Then install ruby-build and update the environment variables with the commands:

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

Ubuntu 16.04

First, update APT:

 apt-get update

Next, install the dependencies:

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

For the next step, you will need to be logged in as the user who will be using Ruby.

For example, if you are installing this for yourself, and your normal (non-root) SSH login is jdoe you would switch to the jdoe user account with the command:

su - jdoe

Switch to this user's home directory with the command:

cd

Install rbenv and update the environment variables with the commands:

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

Then install ruby-build and update the environment variables with the commands:

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

Install Ruby

From this point forward, the process is the same on both CentOS 7 and Ubuntu 16.04.

The next step is to install Ruby.

First, decide which version of Ruby to install. The current version of Ruby, as of this writing, is 2.3.1. You can learn the most recent Ruby version number on the official Ruby download page.

Note: As before, these commands will need to be run as the user who will be using Ruby.

Install Ruby version 2.3.1 (or your version of choice) with the commands:

rbenv install -v 2.3.1
rbenv global 2.3.1

Then install the bundler with the command:

gem install bundler

To verify the installation, use the command:

ruby -v 

If Ruby was installed correctly, the server will reply:

[user@localhost ~]$ ruby -v
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]

Install Rails

The final step is to install Rails.

Note: As before, these commands will need to be run as the user who will be using Ruby.

First, decide which version of Ruby on Rails to install. The current version of Ruby, as of this writing, is 5.0.0.1. You can learn the most recent Ruby on Rails version number on the official Ruby on Rails website.

Install Ruby on Rails with the command:

gem install rails -v 5.0.0.1

After doing this, run the rehash command:

rbenv rehash

To verify the installation, use the command:

rails -v

If Rails was installed correctly, the server will reply:

[user@localhost ~]$ rails -v
Rails 5.0.0.1

Content provided by 1&1

Comments

Tags: Ruby on Rails