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.
(Note) A similar Ruby version control tool has "RVM", but rbenv and RVM are incompatible, so prepare an environment that does not include "RVM".
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.
The flow is like this. 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.
sudoto your head.
apt-get install git
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.
sudoto your head.
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. ..
|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.|
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
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
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
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, the path will be added as double or triple, right? But change .bashrc However, it's strange to do
source ~ / .profile.
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.
You can install each version of ruby with the
rbenv install command.
rbenv install -l to see which stable versions you can install.
$ rbenv install -l 2.5.8 2.6.6 2.7.1 jruby-188.8.131.52 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
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
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>