Skip to main content

Linux offline installation of Ruby and RubyGems environment

Linux offline installation of Ruby and RubyGems environment

Article directory

  • Introduction
  • 1. Install GCC environment
  • 2. Install ruby
  • 3. Install RubyGems
  • 4. Install redis-xxx.gem

Tip: The following is the text of this article. The Redis series of learning will be continuously updated.

Introduction

When learning Redis cluster, I feel confused about the concepts and relationships of these words, so I will sort them out here.

  1. What is Ruby?
    It is a language that can be used to write scripts and run in a Ruby environment.

  2. What are RubyGems?
    It is a tool for managing Ruby scripts. It seems that you can connect to ruby ​​script sources and download and install ruby ​​scripts online.
    Perhaps it is similar to front-end node, Java's maven, or management tools such as rpm and yum.

  3. What is redis-xxx.gem?
    A script for connecting redis to ruby.

  4. What is redis-trib.rb?
    Based on the cluster commands provided by redis, it is encapsulated into an operation tool.
    It is a script file written in ruby ​​by the redis author and used in the src directory.

1. Install GCC environment

Installing Ruby requires relying on the GCC environment. First check whether GCC has been installed on Linux. If not, you need to install it.
Check whether GCC is installed, you can look at the version number.

    gcc -v

If GCC is already installed, the following information will be displayed.
Linux offline installation of Ruby and RubyGems environment
If there is no information, we will install GCC online.

    yum -y install gcc

Back to table of contents…

2. Install ruby

  • Ruby, a simple and fast object-oriented (object-oriented programming) scripting language.
  • The Redis cluster mode is generally 3 masters and 3 slaves, and requires Ruby to assist in the construction.

①Download ruby ​​installation package

Download a certain version of ruby. I chose version 2.3.1 here.
Domestic mirror address: https://cache.ruby-china.com/pub/ruby/

    wget https://cache.ruby-china.com/pub/ruby/ruby-2.3.1.tar.gz

②Unzip the installation package

    tar -zxvf ruby-2.3.1.tar.gz

③Install ruby-2.3.1

    # 进入目录
cd ruby-2.3.1
# 编译,执行配置
./configure
# 安装, 需要好久,过程中不动并不是卡了,而是确实需要那么久
make && make install
# 验证
ruby -v

Linux offline installation of Ruby and RubyGems environment
Successful installation!

④Configure Ruby environment variables

First check whether environment variable configuration is required.

    # 使用命令
which ruby

Linux offline installation of Ruby and RubyGems environment

If the above picture appears, it means that the environment variables are not configured.

    vim /etc/profile
# 按下i键进入编辑模式,在文件最后 PATH上添加ruby安装路径。没有PATH,则这样写。
export PATH=$PATH:/root/ruby-2.3.1/bin

Finally, you need to execute the command # source /etc/profileto take effect immediately. If you use it again at this time, # which rubythe corresponding information will appear.

    source /etc/profile

Configuration successful!

Back to table of contents…

3. Install RubyGems

  • RubyGems is a package manager for the Ruby programming language, which can easily install, uninstall, update, publish and share Ruby libraries and program components. It avoids the standard extra steps of publishing a usable gem (such as an experimental new feature) online so that others can easily install and use it.

  • RubyGems supports a variety of package formats, such as .gem, .tgz, .zip, etc. You can decompress and install a Gem package, and then load it in its execution environment.

①Download rubygems installation package

    wget https://rubygems.org/rubygems/rubygems-2.7.7.tgz

②Extract to the specified directory

    tar -zxvf rubygems-2.7.7.tgz

③Enter the rubygems directory and execute the following command

    cd rubygems-2.7.7
ruby setup.rb
# 当出现 Rubygems-2.7.7 installed时,表示已经成功安装

④Verify installation

    gem -v

⑤Configure Ruby environment variables

First check whether environment variable configuration is required.

    # 使用命令
which gem

Linux offline installation of Ruby and RubyGems environment

If the above picture appears, it means that the environment variables are not configured.

    vim /etc/profile
# 按下i键进入编辑模式,在文件最后 PATH上添加gem安装路径。
export PATH=$PATH:/root/ruby-2.3.1/bin:/root/rubygems-2.7.7/bin

Finally, you need to execute the command # source /etc/profileto take effect immediately. If you use it again at this time, # which gemthe corresponding information will appear.

    source /etc/profile

Configuration successful!

Back to table of contents…

4. Install redis-xxx.gem

An error occurs when executing redis-trib.rb because redis-xxx.gem is missing.
Linux offline installation of Ruby and RubyGems environment

I installed it locally using ready-made files. If you are afraid of stepping into the pitfalls of version tools, it seems that you can download it directly from the official website.
Foreign mirror
domestic ruby ​​gems mirror

Ready-made files are provided here: redis-3.2.0.gem extraction code: krfe

Put the file into the linux opt directory and execute it in the opt directory:

    gem install --local redis-3.2.0.gem

If there are still problems at this time, please refer to the article: https://www.jianshu.com/p/c38369097448/

Back to table of contents…


Summary :
Tip: Here is a summary of the article:
This article is about learning Redis. Download and install the tools needed for Redis cluster in Linux environment: ruby, rubygem, redis.gem. The following learning content will be continuously updated! ! !