ruby rbenv ruby command not found problem solving

Introduction

This post would demo how to solve the “ruby command not found” after installing the ruby using rbenv, eg. When you input this command to install ruby:

rbenv install --verbose 2.5.1

After install successfully , you input :

ruby -v

You got this:

-bash: ruby: command not found

ok, let’s begin to solve this.

Environments

  • rbenv 1.1.1-30-gc8ba27f with plugin ‘ruby-build’ installed
  • ruby 2.5.1 installed by rbenv
  • OS CentOS 6.8

Debug

Before knowing how to solve this problem, let’s check it first by using the rbenv doctor:

curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-doctor | bash

You got this:

Checking for `rbenv' in PATH: /root/.rbenv/bin/rbenv
Checking for rbenv shims in PATH: not found
  The directory `/root/.rbenv/shims' must be present in PATH for rbenv to work.
  Please run `rbenv init' and follow the instructions.
Checking `rbenv install' support: which: no rbenv-install in (/root/.rbenv/bin:/usr/lib/qt-3.3/bin:/opt/mysql57/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)
/root/.rbenv/plugins/ruby-build/bin/rbenv-install (ruby-build 20180329-3-g4dac7b1)
Counting installed Ruby versions: 1 versions
Checking RubyGems settings: OK
Auditing installed plugins: OK

We found that we can run rbenv init to check the problem:

rbenv init
# Load rbenv automatically by appending
# the following to ~/.bash_profile:

eval "$(rbenv init -)"

Problem solving

After debuging, We know that we have missed to append something to ~/.bash_profile,so we open ~/.bash_profile, and append the ** eval “$(rbenv init -)” ** to it, the file looks like this:

export PATH="$HOME/.rbenv/bin:$PATH"
export RBENV_VERSION=2.5.1
eval "$(rbenv init -)"

Then you can logout and login again, run this:

[root@myserver2 ~]# ruby -v
ruby 2.5.1p57 (2018-03-29 revision 63029) [i686-linux]

You can find detail documents about the ruby here: