Ruby Installation Unix
The following lists the steps for installing Ruby on a Linux machine.
**Note:** Before installation, please ensure you have root privileges.
* * *
## Source Code Installation
* Download the latest Ruby compressed file. (http://www.ruby-lang.org/en/downloads/).
* After downloading Ruby, extract it to a newly created directory:
$ tar -xvzf ruby-2.2.3.tgz $ cd ruby-2.2.3
* Now, configure and compile the source code as shown below:
$ ./configure $ make $ sudo make install
* After installation, ensure everything is working correctly by entering the following command in the command line:
$ruby -v ruby 2.2.3β¦β¦
* If everything is working correctly, it will output the version of the installed Ruby interpreter, as shown above. If you installed a different version, a different version will be displayed.
## Automatic Ruby Installation
If your computer is already connected to the Internet, the simplest way to install Ruby is to use **yum** or **apt-get**. Enter the following commands at the command prompt to install Ruby on your computer.
$ sudo yum install ruby # For CentOS, Fedora, or RHEL systems
or
sudo apt-get install ruby-full # For Debian or Ubuntu systems
If you are on an Apple system, you can use the **brew** command to install:
$ brew install ruby
* * *
## Installing Ruby with RVM
RVM can install and manage multiple Ruby versions on your system. It also manages different gem sets. It supports OS X, Linux, and other UNIX-like operating systems.
### Installing RVM
$ gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB $ curl -sSL https://get.rvm.io | bash -s stable
After installation is complete, some installation information will be listed, with one line to note:
...To start using RVM you need to run `source /etc/profile.d/rvm.sh`....
This means that to start using it, you need to execute a source command to re-execute the newly modified initialization file. According to the installation prompt, execute the following command to load the RVM environment (you don't need to do this if you open a new Terminal, as it will reload automatically):
source /etc/profile.d/rvm.sh
Check if the installation was successful:
$ rvm -v rvm 1.22.17 (stable) by Wayne E. Seguin , Michal Papis [https://rvm.io/]
### Installing Ruby Environment with RVM
List known Ruby versions:
$ rvm list known
You can choose an existing RVM version to install (the following uses RVM version 2.4.2 as an example):
$ rvm install 2.4.2
Similarly, continue to wait for the lengthy download and compilation process. Once completed, Ruby and Ruby Gems will be installed.
### Common RVM Commands
Query installed Ruby versions:
$ rvm list
Uninstall an installed version:
$ rvm remove 1.9.2
**Setting the Ruby Version**
After RVM is installed, you need to execute the following command to set a specific Ruby version as the system default:
$ rvm 2.0.0 --default
Similarly, you can use other version numbers, provided you have installed that version using `rvm install`.
At this point, you can test if it's correct:
$ ruby -v ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin13.0.0] $ gem -v 2.1.6
This might be because the default source for Ruby is cocoapods.org, and accessing this URL from within China can sometimes be problematic. An online solution is to replace the source with ruby-china. The replacement method is as follows:
$ gem source -r https://rubygems.org/ $ gem source -a https://gems.ruby-china.com/
To verify if the replacement was successful, you can execute:
$ gem sources -l
The normal output should be:
*** CURRENT SOURCES *** https://gems.ruby-china.com/
Please ensure only gems.ruby-china.com is listed.
$ gem install rails
**If you are using Gemfile and Bundler (e.g., a Rails project)**
You can use Bundler's Gem source mirror command.
$ bundle config mirror.https://rubygems.org https://gems.ruby-china.com
This way, you don't need to change the source in your Gemfile.
source 'https://rubygems.org/' gem 'rails', '4.1.0'...
YouTip