Ruby Installation - Linux
Below are the steps to install Ruby on a Linux machine.
Note:Before installation, please make sure you have root privileges.
Source Code Installation
- Download the latest Ruby compressed 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 shown below:
$ ./configure $ make $ sudo make install
- After installation, enter the following command in the command line to make sure everything works properly:
$ruby -v ruby 2.2.3……
- If everything works properly, the version of the installed Ruby interpreter will be output, as shown above. If you have installed another version, a different version will be displayed.
Automatically Install Ruby
If your computer is already connected to the Internet, the simplest way to install Ruby is to useyumorapt-get. In the command prompt, enter the following command to install Ruby on your computer.
$ sudo yum install ruby # CentOS, Fedora, 或 RHEL 系统 或 sudo apt-get install ruby-full # Debian 或 Ubuntu 系统
If you are on a Mac system, you can usebrewcommand to install:
$ brew install ruby
Install Ruby with RVM
RVM can install and manage multiple Ruby versions on the system. It can also manage different gem sets. It supports 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 installation, some installation information will be listed, and one line requires attention:
... 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 newly modified initialization file. According to the installation prompt, run the following command to load the RVM environment (you don't need to do this if you open a new Terminal, as it will automatically reload).
source /etc/profile.d/rvm.sh
Check whether the installation is correct
$ rvm -v rvm 1.22.17 (stable) by Wayne E. Seguin <[email protected]>, Michal Papis <[email protected]> [https://rvm.io/]
Use RVM to Install the Ruby Environment
List the known Ruby versions:
$ rvm list known
You can choose an existing rvm version to install (the following is an example of installing rvm version 2.4.2)
$ rvm install 2.4.2
Similarly, continue to wait for the lengthy download and compilation process. Once complete, Ruby and Ruby Gems will be installed.
RVM Common Commands
Query installed Ruby versions
$ 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 Ruby version as the system default.
$ rvm 2.0.0 --default
Similarly, you can use other version numbers, provided that you have installed that version with 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 Ruby's default source uses cocoapods.org, which can sometimes be problematic to access from China. One solution found online is to replace the source with ruby-china's, as follows:
$ gem source -r https://rubygems.org/ $ gem source -a https://gems.ruby-china.com/
To verify whether the replacement was successful, you can run:
$ gem sources -l
Normal output result:
*** CURRENT SOURCES *** https://gems.ruby-china.com/
Please make sure there is only gems.ruby-china.com
$ gem install rails
If you use Gemfile and Bundle (e.g., Rails projects)
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' ...<div style="display:none;"> <hr> <h2 id="cs-ruby">Cloud Studio </h2> <p> <a target="_blank" href='https://studio.dev.tencent.com/' rel="noopener noreferrer">Cloud Studio</a> is a browser-based integrated development environment that supports most programming languages, including HTML5, PHP, Python, Java, Ruby, C/C++, .NET, etc. No download or installation is required, and you can switch development environments with one click. <a target="_blank" href='https://studio.dev.tencent.com/' rel="noopener noreferrer">Cloud Studio</a> provides a complete Linux environment, supports custom domain name resolution, and dynamic computing resource adjustment, allowing you to complete the development, compilation, and deployment of various applications.</p><p><img src='https://dn-coding-net-production-pp.qbox.me/1a0d4ed6-cd32-4e60-bad2-e6140fa556cb.png' alt='' /></p> <p>Now CODING is hosting a "My Favorite Cloud Studio Plugin Contest" based on the Cloud Studio workspace. Visit the official event website: <a href="https://studio.qcloud.coding.net/campaign/favorite-plugins/index" rel="noopener noreferrer" target="_blank">https://studio.qcloud.coding.net/campaign/favorite-plugins/index</a> to learn more about the event.</p> </div> Other Extensions