English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The following lists the steps to install Ruby on a Linux machine.
Note:Before installation, please make sure you have root privileges.
Download the latest version of the Ruby compressed file.Please click here to download.
After downloading Ruby, unzip it into the 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, enter the following command in the command line to ensure everything is working properly:
$ruby -v ruby 2.2.3……
If everything works as expected, it will output the version of the installed Ruby interpreter, as shown above. If you have installed another version, it will display a different version.
If your computer is connected to the Internet, the simplest way to install Ruby is to use yum or apt-get. Enter the following command in 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 or Ubuntu system
If you are using an Apple system, you can use brew Command installation:
$ brew install ruby
RVM can install and manage multiple Ruby versions in the system. It can also manage different gem sets. It supports OS X, Linux, and other UNIX-like operating systems.
$ gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB $ curl -sSL https://get.rvm.io | bash -s stable
After installation, some installation information will be listed, one line of which is worth noting:
... To start using RVM, you need to run `source /etc/profile.d/rvm.sh` ....
This means that to start using it, you need to run a source command to re-execute the recently modified initialization file. According to the installation prompts, execute the following command to load the RVM environment (you don't need to do this when opening a new Termal, as it will automatically reload it)
source /etc/profile.d/rvm.sh
Check if it is installed correctly
$ rvm -v rvm 1.22.17 (stable) by Wayne E. Seguin <[email protected]>, Michal Papis <[email protected]> [https://rvm.io/]
List known ruby versions:
$ rvm list known
You can choose an existing RVM version to install (the following takes rvm as an example) 2.4.2 take the installation of a version as an example)
$ rvm install 2.4.2
Similarly, continue to wait for the long download and compilation process. After completion, Ruby and Ruby Gems are installed.
Query already installed ruby
$ rvm list
Uninstall an installed version
$ rvm remove 1.9.2
Set Ruby Version
After RVM is installed, you need to run the following command to set the specified version of Ruby as the system default version
$ rvm 2.0.0 --default
Similarly, you can also use other version numbers, provided that you have installed that version using rvm install
At this point, you can test whether it is correct
$ 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 accessing this website from within China sometimes has issues. One solution on the internet is to replace it with ruby-china's, the replacement method is as follows:
$ gem source -r https://rubygems.org/ $ gem source -a https://gems.ruby-china.com/
要想验证是否替换成功了,可以执行:
$ gem sources -l
正常的输出结果:
*** CURRENT SOURCES *** https://gems.ruby-china.com/
请确保只有 gems.ruby-china.com
$ gem install rails
如果你使用 Gemfile 和 Bundle (例如:Rails 项目)
你可以用 Bundler 的 Gem 源代码镜像命令。
$ bundle config mirror.https://rubygems.org https://gems.ruby-china.com
这样你不用改你的 Gemfile 的 source。
source 'https://rubygems.org/' gem 'rails', '4.1.0' ...