[Ruby] Building a Ruby development environment on Ubuntu

Introduction

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
	PATH="$HOME/.rbenv/bin:$PATH"
fi

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
2.5.8
2.6.6
2.7.1
jruby-9.2.12.0
maglev-1.0.0
mruby-2.1.1
rbx-5.0
truffleruby-20.1.0

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
irb(main):002:0> 

Recommended Posts

[Ruby] Building a Ruby development environment on Ubuntu
Building a Ruby environment for classes on Mac
Create a development environment for Ruby 3.0.0 and Rails 6.1.0 on Ubuntu 20.04.1 LTS
Build a Ruby on Rails development environment on AWS Cloud9
Build a XAMPP environment on Ubuntu
Difficulties in building a Ruby on Rails environment (Windows 10) (SQLite3)
Building a Lambda development environment in Eclipse
Building a Kotlin development environment using SDKMAN
Build a Java development environment on Mac
Build a development environment where Ruby on Rails breakpoints work on Windows
Steps to build a Ruby on Rails development environment with Vagrant
Install Ruby on Ubuntu 20.04
Building a Hadoop cluster (Cloudera Manager on Ubuntu 18.04)
[Java] Build Java development environment on Ubuntu & check execution
Ruby on Rails development environment construction on M1 Mac
How to build a Pytorch environment on Ubuntu
Minimal steps to set up a Ruby environment with rbenv on Ubuntu 20.04
Building a development environment for Flutter on Win10 --- Flutter SDK Install (2020 preservation version)
How to build a Ruby on Rails development environment with Docker (Rails 6.x)
How to build a Ruby on Rails development environment with Docker (Rails 5.x)
Template: Build a Ruby / Rails development environment with a Docker container (Ubuntu version)
Create a Java development environment using jenv on Mac
Building WebGIS on Ubuntu20.04 LTS
[Environment construction] Ruby on Rails 5.2 system development environment construction [within 1 hour]
Docker the development environment of Ruby on Rails project
Let's create a gcloud development environment on a centos8 container
Ruby Learning # 11 Building a Calculator
Ruby installation on WSL2 + Ubuntu 20.04
Ruby Learning # 32 Building a Quiz
Build a development environment to create Ruby on Jets + React apps with Docker
Ruby ① Build a Windows environment
A memo when building a Rails 5.2 development environment using Docker Desktop + WSL2 on Windows 10 Home
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
Docker × Java Building a development environment that is too simple
[Procedure 1 for beginners] Ruby on Rails: Construction of development environment
[Environment construction] Get the Ruby on Rails 6 development environment within 1 hour
Use the high-performance SQL development tool "A5: SQL Mk-2" on Ubuntu
Ruby Learning # 19 Building a Better Calculator
Ruby Learning # 22 Building a Guessing Game
Ruby on Rails 6.0 environment construction memo
Install ruby on Ubuntu 20.04 with rbenv
Build Unity development environment on docker
Install Java development environment on Mac
A story I was addicted to before building a Ruby and Rails environment using Ubuntu (20.04.1 LTS)
A story of frustration trying to create a penetration environment on Ubuntu 20.04
Ruby on Rails --From environment construction to simple application development on WSL2
Ruby on Rails development environment construction with Docker + VSCode (Remote Container)
Procedure for building a Rails application development environment with Docker [Rails, MySQL, Docker]
From building to deploying Ruby on Jets in docker-compose environment <Part 2>
I tried to create a Spring MVC 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
Create Spring Boot development environment on Vagrant
Build a PureScript development environment with Docker
Java development environment construction memo on Mac
Let's create a Java development environment (updating)
[Docker] Development environment construction Rails6 / Ruby2.7 / MySQL8
Try building a GPU container on GCP.
Build Java 8 development environment on AWS Cloud9
Ruby Learning # 12 Building a Mad Libs Game