In this article, we will discuss how to install RubyGems on Linux. RubyGems is a package manager that allows you to easily install and manage Ruby software packages on your Linux machine.
Before we begin, it is important to note that RubyGems comes pre-installed with Ruby, so if you have Ruby installed on your machine, you should already have RubyGems. However, if you do not have Ruby installed, you can install it using your distribution package manager.
Once you have Ruby installed, you can check whether or not RubyGems is installed by running the following command in your terminal:
gem --version
If you see a version number returned, then RubyGems is already installed on your machine. If not, you will need to install it manually.
To install RubyGems on Linux, follow the steps below:
Install the RubyGems on Linux (Ubuntu)
The first step in installing RubyGems on Linux is to install the RubyGems package. To do this, open your terminal and type the following command:
sudo apt-get install rubygems
This command will install the RubyGems package on your machine.
Update RubyGems on Linux
Once RubyGems is installed, you should update it to the latest version. To do this, run the following command:
sudo gem update --system
This command will update RubyGems to the latest version available.
Install RubyGems dependencies
RubyGems requires some dependencies to function properly. To install these dependencies, run the following command:
sudo apt-get install build-essential
sudo apt install ruby-full
This command will install the necessary dependencies for RubyGems to function.
Verify the installation
To verify that RubyGems is installed correctly, run the following command:
gem -v
This command should return the version number of RubyGems that you just installed.
Install a gem
Now that RubyGems is installed and functioning properly, you can use it to install gems. To install a gem, run the following command:
sudo gem install <gemname>
Replace <gemname>
with the name of the gem you want to install. For example, to install the rails
gem, you would run the following command:
sudo gem install rails
This command will install the rails
gem and any necessary dependencies.
Install the RubyGems on Linux (CentOS)
Update your system
Before installing RubyGems, it is recommended to update your system to ensure that you have the latest software packages installed. To update your CentOS system, run the following command:
sudo yum update
Install Ruby and RubyGems on Linux
CentOS comes with a version of Ruby installed by default, but it may not include RubyGems. To install Ruby and RubyGems on CentOS, run the following command:
sudo yum install ruby rubygems
This command will install both Ruby and RubyGems on your system.
Verify the installation
After installing Ruby and RubyGems, you can verify that they are installed correctly by running the following commands:
[root@Virtono-Tutorials ~]# ruby -v
ruby 2.0.0p648 (2015-12-16) [x86_64-linux]
[root@Virtono-Tutorials ~]# gem -v
2.0.14.1
[root@Virtono-Tutorials ~]#
These commands should return the version numbers of Ruby and RubyGems respectively.
Install a gem
To install a gem using RubyGems on CentOS, you can use the same command as on other Linux distributions:
sudo gem install <gemname>
Replace <gemname>
with the name of the gem, you want to install. For example, to install the rails
gem, you would run the following command:
sudo gem install rails
This command will install the rails
gem and any necessary dependencies.
How to fix the following error:
[root@Virtono-Tutorials ~]# sudo gem install rails
Fetching: concurrent-ruby-1.2.2.gem (100%)
ERROR: Error installing rails:
concurrent-ruby requires Ruby version >= 2.3.
[root@Virtono-Tutorials ~]#
Install a newer version of Ruby
If your version of Ruby is older than 2.3, you will need to install a newer version. There are several ways to do this, but one of the most common is to use a Ruby version manager such as rvm
or rbenv
.
# sudo yum install -y git curl zlib-devel gcc-c++ patch readline readline-devel \
libyaml-devel libffi-devel openssl-devel make bzip2 autoconf automake libtool bison sqlite-devel
# git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
source ~/.bashrc
# git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
# rbenv install 2.3.8
#rbenv global 2.3.8
Note: Remove “#”
0 Comments