Ubuntu 12 - How to Install Ruby and Rails Correctly

Ubuntu 12 - how to install Ruby and Rails correctly

Follow this and enjoy

Install Ruby and Rails completely with chruby

Install Ruby on Rails using rvm on Ubuntu 12.04

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 installin
g 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.

How do I install ruby 2.0.0 correctly on Ubuntu 12.04?

follow below steps

sudo apt-get -y update
sudo apt-get -y install build-essential zlib1g-dev libssl-dev libreadline6-dev libyaml-dev
cd /tmp
wget http://cache.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p481.tar.gz
tar -xvzf ruby-2.0.0-p481.tar.gz
cd ruby-2.0.0-p481/
./configure --prefix=/usr/local
make
sudo make install

Install Ruby on Rails on Ubuntu 12.04 LTS

I suggest you to use rbenv, it is a little bit longer to install but it's way more flexible. Among other feature it allow you to install different versions of ruby on you system, and specify which version to use for each project (or conveniently to use a global version everywhere).

I got a doc you can follow, it works very well and I installed several machine with it. If you already installed rbenv, rvm, gem, ruby or rails please remove them before starting

  • Works perfectly with Ubuntu 12.04, minor adjustments could be required for other distro
  • Some commands need super-user access, I prefixed them with sudo and it will ask for your password
  • This will install rbenv and all the gems in /opt

Here is the step by step, just copy and paste in your terminal:

* update and install packages *

sudo apt-get update && apt-get -y upgrade
sudo apt-get install -y vim tmux git curl zlib1g-dev build-essential libssl-dev libreadline-dev libxml2 libxslt1-dev libxml2-dev nodejs libapr1-dev libcurl4-gnutls-dev

* install rbenv *

cd /opt
sudo git clone git://github.com/sstephenson/rbenv.git rbenv

We will give your basic user full access to rbenv directory, this is needed so you won't have to use sudo for the rest of the procedure, or when updating/installing gems.

Replace yourself by your user name:

sudo chown -R yourself:yourself /opt/rbenv

* setup rbenv *

sudo touch /etc/profile.d/rbenv
sudo echo 'export RBENV_ROOT=/opt/rbenv' >> /etc/profile.d/rbenv
sudo echo 'export PATH=/opt/rbenv/bin:$PATH' >> /etc/profile.d/rbenv
sudo echo 'eval "$(rbenv init -)"' >> /etc/profile.d/rbenv

* setup rbenv over ssh connection *

This step needs to be done with super-user privileges

Edit /root/.bashrc file, and add the line source /etc/profile.d/rbenv before the line [ -z "$PS1" ] && return

Do the same in /home/yourself/.bashrc file

* install ruby *

exec $SHELL
mkdir -p $RBENV_ROOT/plugins
cd $RBENV_ROOT/plugins
git clone git://github.com/sstephenson/ruby-build.git
echo 'export PATH="$RBENV_ROOT/plugins/ruby-build/bin:$PATH"' >> /etc/profile.d/rbenv
exec $SHELL

Those 2 lines install ruby and set the installed version by default, you can choose another version of ruby is you wish. Typing in your terminal rbenv install and tapping on the TAB key will display a list of available ruby versions

rbenv install 1.9.3-p392
rbenv global 1.9.3-p392

* verify ruby *

ruby -v

The output should be ruby 1.9.3p392 (2013-02-22 revision 39386) [x86_64-linux] or any other version you would have installed. This command should not give you any error

* install base gems *

gem install --no-rdoc --no-ri bundler rake 
rbenv rehash

* install rails *

bundle exec gem install rails -v 3.0.1

* other commands *

from now on any commands passed to Rails or Rake must be prefixed by bundle exec that will ensure all your environment is correctly loaded

  • Start rails server bundle exec rails s
  • Start Rails console bundle exec rails c
  • migrate database bundle exec rake db:migrate

"Bundle" commands can be ran directly, ex bundle update

Properly installing Ruby enviroment for Ubuntu 12.04?

I did follow what this answer suggested.

I had already installed the mentioned packages first so I didn't have to re make anything.

It worked like charm, hope it helps in future.

ubuntu 12.04 ruby 2.0 rails: Could not find 'thread_safe'

Seems you are using 2.1.0 version of rubygems. It's not bug of tread_safe or atomic gems, but it's bug of rubygems 2.1.0. Try to install older version (like 2.0.8). How to do this:

gem uninstall rubygems-update
gem install rubygems-update --version 2.0.8
update_rubygems

Using RVM on Ubuntu 12.04 to use Rails. The program 'rails' is currently not installed

You need to type source ~/.rvm/scripts/rvm before attempting to use Rails.

I believe the RVM installation suggests putting this line (or something similar) in your .bashrc.

Run the following command in Terminal:

echo "source \$HOME/.rvm/scripts/rvm" >> ~/.bashrc

This appends the line source \$HOME/.rvm/scripts/rvm to the end of the .bashrc file.

Doing so ensures that RVM is properly loaded each time you open up a terminal.



Related Topics



Leave a reply



Submit