Ruby installation-Linux
The steps for installing Ruby on a Linux machine are listed below.
Note: before installing, make sure you have root permissions.
Source code installation
Download the latest version of the Ruby zip file. Please click here to download .
After downloading Ruby, extract it to the newly created directory:
$ tar -xvzf ruby-2.2.3.tgz
$ cd ruby-2.2.3
Now, configure and compile the source code, as follows:
$ ./configure
$ make
$ sudo make install
After installation, ensure that everything works properly by entering the following command on the command line:
$ruby -v
ruby 2.2.3……
If everything works fine, the installed version of the Ruby interpreter willbe output, as shown above. If you have another version installed, differentversions are displayed.
Automatically install Ruby
If your computer is already connected to Internet, the easiest way to install Ruby is to use the yum
or apt-get
. Enter the following command at the command prompt to install Ruby on your computer.
$ sudo yum install ruby # CentOS, Fedora, or RHEL system
or
sudo apt-get install ruby-full # Debian 或 Ubuntu 系统
If you are an Apple system, you can use the brew
command installation:
$ brew install ruby
Install Ruby using RVM
RVM can install and manage multiple Ruby versions in the system. At the sametime can manage different gem
set. Support for OS X, Linux, and other UNIX-like operating systems.
Install RVM
$ gpg --keyserver hkp://keys.gnupg.net --recv-keys
409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
$ curl -sSL https://get.rvm.io | bash -s stable
After the installation is complete, some installation information is listed,including one line to note:
...
To start using RVM you need to run `source /etc/profile.d/rvm.sh`
....
It means that if you want 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 (the new Termal does not have to do this, it will reloadautomatically)
source /etc/profile.d/rvm.sh
Check to see if it is installed correctly
$ rvm -v
rvm 1.22.17 (stable) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]
Install the Ruby environment with RVM
List known ruby versions:
$ rvm list known
You can choose an existing version of rvm to install (take the installation of rvm version 2.4.2 as an example)
$ rvm install 2.4.2
Also continue to wait for the long download and compilation process, and when it is complete, Ruby and Ruby Gems will be installed.
Rvm common commands
Query the installed ruby
$ rvm list
Uninstall an installed version
$ rvm remove 1.9.2
Set Ruby version
After RVM is installed, you need to execute the following command to set thespecified version of Ruby as the system default version
$ rvm 2.0.0 --default
Similarly, you can use other version numbers, as long as you are useful rvm install
installed that version.
At this time, you can test whether it is correct or not.
$ ruby -v
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin13.0.0]
$ gem -v
2.1.6
This may be because the default source of Ruby uses cocoapods.org, and it issometimes difficult to access this URL in China. One solution on the Internet is to replace the remote source with ruby-china, as follows:
$ gem source -r https://rubygems.org/
$ gem source -a https://gems.ruby-china.com/
To verify that the replacement was successful, execute:
$ gem sources -l
Normal output:
*** CURRENT SOURCES ***
https://gems.ruby-china.com/
Please make sure that only gems.ruby-china.com
$ gem install rails
If you use Gemfile and Bundle (for example, Rails project)
You can use Bundler’s Gem source code mirror command.
$ bundle config mirror.https://rubygems.org https://gems.ruby-china.com
So you don’t have to change your Gemfile source.
source 'https://rubygems.org/'
gem 'rails', '4.1.0'
...