Ruby, a dynamic, open-source programming language, is widely used for its simplicity and speed. However, while installing Ruby on Ubuntu 20.04, you may encounter the “BUILD FAILED” error. This article will provide a step-by-step guide on how to resolve this issue.
To fix the "BUILD FAILED" error when installing Ruby on Ubuntu 20.04, you need to ensure that you have all the necessary dependencies installed, such as build-essential, tklib, zlib1g-dev, libssl-dev, libffi-dev, libxml2, libxml2-dev, libxslt1-dev, and libreadline-dev. Additionally, you will need to install rbenv and ruby-build, update your shell configuration, and then proceed with installing the desired Ruby version using rbenv. Finally, set the installed Ruby version as the global default and verify the installation.
Before we start, ensure that you have superuser privileges or access to an account with
sudo permissions. You will also need a terminal window or command line prompt.
Installing Necessary Dependencies
The first step in resolving the “BUILD FAILED” error is to ensure that you have all the necessary dependencies installed on your Ubuntu system. These dependencies are required to build Ruby from source. Run the following command:
sudo apt install -y build-essential tklib zlib1g-dev libssl-dev libffi-dev libxml2 libxml2-dev libxslt1-dev libreadline-dev
sudo: This command allows you to run the following command with superuser privileges.
apt install: This command installs the specified packages.
-y: This option automatically answers ‘yes’ to all prompts.
- The rest of the command lists the packages that will be installed.
Installing rbenv and ruby-build
The next step is to install
rbenv provides an easy way to install and manage versions of Ruby, and
ruby-build is a plugin that adds the
rbenv install command.
Run the following commands to clone
ruby-build from their GitHub repositories:
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
git clone: This command clones a repository into a new directory.
- The URLs are the locations of the
~/.rbenv/plugins/ruby-buildare the directories where
ruby-buildwill be installed.
Updating Shell Configuration
Next, update your shell configuration file to include
rbenv. Add the following lines to the end of your
eval "$(rbenv init -)"
export PATH="$HOME/.rbenv/bin:$PATH": This line adds
PATH, allowing you to run
eval "$(rbenv init -)": This line initializes
After adding these lines, save the file and reload the shell configuration by running
source ~/.bash_profile, or
Now you’re ready to install Ruby. Run the following command, replacing
VERSION with the desired Ruby version (e.g.,
rbenv install VERSION
If you encounter an error related to downloading the Ruby source file, you can manually download it from the official Ruby website and save it as
ruby-VERSION.tar.gz in the
Setting the Default Ruby Version
After the installation completes successfully, set the installed Ruby version as the global default:
rbenv global VERSION
VERSION with the Ruby version you installed.
Verifying the Installation
Finally, verify that Ruby is installed correctly by running
ruby -v. It should display the installed Ruby version.
By following these steps, you should be able to resolve the “BUILD FAILED” error when installing Ruby on Ubuntu 20.04. If you encounter any further issues, please provide more specific details or error messages for further assistance.
rbenv provides an easy way to install and manage versions of Ruby, while
ruby-build is a plugin that adds the
rbenv install command. Together, they make it simple to install and switch between different versions of Ruby on your system.
You can check if you have superuser privileges or
sudo access by running the
sudo -v command. If you have the necessary privileges, it will not prompt you for a password and will simply return to the command prompt. If you do not have the necessary privileges, it will prompt you for a password or display an error message.
Yes, you can install a specific version of Ruby using rbenv. When running the
rbenv install command, specify the desired Ruby version as the argument (e.g.,
rbenv install 3.0.3). rbenv will download and install the specified version of Ruby.
To switch between different versions of Ruby, use the
rbenv global command followed by the desired Ruby version (e.g.,
rbenv global 3.0.3). This sets the specified version as the global default. Alternatively, you can use the
rbenv local command to set a specific version for a particular directory.
To uninstall a Ruby version installed using rbenv, use the
rbenv uninstall command followed by the Ruby version you want to remove (e.g.,
rbenv uninstall 3.0.3). This will remove the specified Ruby version from your system.