[Ruby] Building a Ruby development environment on Ubuntu


As of July 7, 2020, I tried to build a Ruby environment, so I will transcribe it. There are quite a lot of people writing articles, but if you output it yourself, it will be a learning experience.

Installation environment

(Note) A similar Ruby version control tool has "RVM", but rbenv and RVM are incompatible, so prepare an environment that does not include "RVM".

What to put

Also include a tool called rbenv that can manage multiple Ruby versions. Not only can you enter multiple Ruby versions, but you will also be able to specify the Ruby version to use for each project. In addition, although it is treated as an option of rbenv (?), Ruby-build will also be introduced.

Big flow

The flow is like this. 0. Install git.

  1. Install the necessary tools and packages in advance.
  2. Installation of rbenv and environment settings
  3. Install ruby-build
  4. Install Ruby

Step 0. Install git

Although git itself is not directly related to environment construction, it is downloaded from github when installing rbenv and ruby-build. For this reason, please include git in advance. The installation method is described in here, but it is completed with one ʻapt-get` command.

apt-get install git

Step 1. Install required tools and packages

Details are written in here, but since it is in English, ... When downloading and installing the required version of Ruby with rbenv + ruby-build, a compile error may occur due to the difference in environment, so at least the following packages should be included in advance. That's right.

If you want to put it all at once, copy and paste the long command below and execute it.

apt-get install autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm6 libgdbm-dev libdb-dev

If you cannot use "libgdbm6", try using "libgdbm5". As for what each package is, there are many things that you do not know even if you try to find out, but it seems that you will not know until you need it and use it, so if you are interested, please check each one. ..

[Supplement] List of required packages in advance (I checked it myself)
* As of July 7, 2020, it is the one described in the explanation of ruby-build.
package name What is this? Reaction when I put it in my environment individually
autoconf Automatic script generation tool for configure
bison A type of parser generator. Seems to be used when compiling
build-essential As the name suggests, it seems to contain a set of build tools necessary for development.
libssl-dev SSL-related development toolkit
libyaml-dev YAML related development library
libreadline6-dev It seems to be a GNU readline library, but I'm not sure what it does ... libreadline-Recommended for dev, libncurses-dev was installed as a dependency
zlib1g-dev compression(gzip, pkzip )Library for
libncurses5-dev ncurses related development library. Text-based user interface in a terminal-independent format(TUI)It seems to provide an API for creating
libffi-dev Library for Foreign Function Interface. I think it is used when calling methods written in other languages.
libgdbm6 GNU dbm database routines(Runtime version)
libgdbm-dev GNU dbm database routines(Development file)
libdb-dev Berkeley Database Libraries [development] → libdb5.3-dev has been additionally installed.

Step 2. Install rbenv and configure the environment

2-1. Installation of rbenv

To install rbenv, use git clone to download it from github and place it in the .rbenv folder in your home directory.

git clone https://github.com/sstephenson/rbenv.git ~/.rbenv

2-2. rbenv environment settings 1 Pass through the path

As an environment setting for rbenv, pass the path to ~ / .rbenv / bin. Official states that in the case of Ubuntu desktop environment, add the path setting to .bashrc. So, if you execute the command as below, it's OK.

echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
[Supplement] When writing in .profile instead of .bashrc
Personally, I feel that writing the path setting in .bashrc is somewhat ill-advised. I wonder if it is .profile or .bash_profile if I write environment variables, so I wrote it in .profile in my environment.

If you want to write the path setting in .profile, open .profile with an editor and add the following code.

if [ -d "$HOME/.rbenv/bin" ] ; then

2-3. Environment setting of rbenv 2 Put rbenv init --in .bashrc.

Execute the following command so that rbenv init - is executed in .bashrc.

echo 'eval "$(rbenv init -)"' >> ~/.bashrc

After that, the settings are reflected.

source ~/.bashrc
[Supplement] About putting rbenv init-in .bashrc
The `rbenv init -` command recreates the shims directory and does rehash processing, but this command also adds the path to shims to $ PATH. So it's kind of unpleasant to put it in .bashrc, but I'm doing a lot of other things, so I followed the official instructions.
  • If you put it in .bashrc, every time you change something and reflect the setting with source ~ / .bashrc, the path will be added as double or triple, right? But change .bashrc However, it's strange to do source ~ / .profile.

Step 3. Install ruby-build

Install ruby-build. ruby-build is also published on github, so download it with git clone like rbenv. The location is under the ~ / .rbenv / plugins / directory.

git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build

You can now use the rbenv install command.

Step 4. Install ruby

You can install each version of ruby with the rbenv install command.

First, use rbenv install -l to see which stable versions you can install.

$ rbenv install -l

Only latest stable releases for each Ruby implementation are shown.
Use 'rbenv install --list-all' to show all local versions.

The latest stable version of the regular version of Ruby as of July 7, 2020 seems to be 2.7.1, so when installing that, specify the version.

rbenv install 2.7.1

After installation, use rbenv global to set it as the version of ruby you normally use.

rbenv global 2.7.1

Finally, run rbenv rehash to reflect the installed ruby version in shims. In the future, when you install another version of ruby or add a gem, it seems better to do rbenv rehash.

rbenv rehash

If there are no errors, you can now run ruby. You can check the version with'ruby -v'.

$ ruby -v
Ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-linux]

Also, use ʻirb` to display "Hello, World!".

$ irb
irb(main):001:0> puts "Hello, World!"
Hello, World!
=> nil

Recommended Posts

[Ruby] Building a Ruby development environment on Ubuntu
Build a Ruby on Rails development environment on AWS Cloud9
Build a Java development environment on Mac
Steps to build a Ruby on Rails development environment with Vagrant
Build a development environment to create Ruby on Jets + React apps with Docker
Ruby ① Build a Windows environment
Learn the meaning of "passing the PATH" by building a Java development environment on Mac
[For beginners] Until building a Web application development environment using Java on Mac OS
Install ruby on Ubuntu 20.04 with rbenv
Build Unity development environment on docker
Install Java development environment on Mac
Notes on building Kotlin development environment and migrating from Java to Kotlin
Building a haskell environment with Docker + VS Code on Windows 10 Home
Build Java 8 development environment on AWS Cloud9
Run jooby's Eclipse development environment on Gradle
Build a JMeter environment on your Mac
Muscle Ruby on Rails Day 1 ~ Environment Construction ~
When building rails6 environment on Ubuntu, it gets stuck with bundle install
Introducing Rspec, a Ruby on Rails test framework
[Personal memo] Ruby on Rails environment construction (Windows)
[Ruby on Rails] A memorandum of layout templates
Build a Laravel environment on an AWS instance
[Win10] Build a JSF development environment with NetBeans
(Ruby on Rails6) Creating data in a table
Build a development environment for Docker, java, vscode
Points stuck in building VSCode & Java development environment
Build a Java runtime environment on Sakura VPS
GitLab development environment setup (GDK) on macOS (September 2020)
Create a Spring Boot development environment with docker
I made a portfolio with Ruby On Rails
Build a Java development environment with VS Code
[Environment construction Mac] Ruby on Rails (+ Webpacker handles errors)
What I stumbled upon when installing Ruby on Ubuntu
Install rbenv with apt on ubuntu and put ruby
Create a Java, JavaScript team development environment (problem raising)
A high bill from AWS during development on rails ...
Try to build a Java development environment using Docker
Creating a lightweight Java environment that runs on Docker
Java + Spring development environment construction with VirtualBox + Ubuntu (Xfce4)
Ruby on Rails Elementary
Setting JAVA_HOME on Ubuntu
java development environment construction
Ruby On Rails Association
The story of introducing a very Rails-like serverless framework "Ruby on Jets" into the production environment
Build a "Spring Thorough Introduction" development environment with IntelliJ IDEA
How to display a graph in Ruby on Rails (LazyHighChart)
Build a CentOS 8 virtual environment on your Mac with VirtualBox
Explanation of Ruby on rails for beginners ③ ~ Creating a database ~
Apply CSS to a specific View in Ruby on Rails
Create a Java and JavaScript team development environment (gradle environment construction)
I tried to create a padrino development environment with Docker
[Java development environment construction] Install OpenJDK 11 (Java 11) on macOS with Homebrew.