Target readers: Beginners of Ruby, Python, etc. who are in trouble with this error message
$ fluentd
rbenv: fluentd: command not found
The `fluentd' command exists in these Ruby versions:
2.6.3
If you are using ** env
, such as rbenv or pyenv, you may get an error message like this.
To solve this problem, you need to understand how ** env
works.
** env
worksIn the first place, if you are using ** env
, just moving the directory like this will automatically switch the version of ruby
and python
, but how is this realized? Are you there?
$ ruby --version
ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin18]
$ cd my-project
$ cat .ruby-version
2.4.5
$ ruby --version
ruby 2.4.5p335 (2018-10-18 revision 65137) [x86_64-darwin18]
Actually, the ruby
running here is not the real ruby
! It's a script located in ~ / .rbenv / shims /
.
$ which ruby
/Users/x-xxxxx/.rbenv/shims/ruby
$ cat ~/.rbenv/shims/ruby
#!/usr/bin/env bash
set -e
[ -n "$RBENV_DEBUG" ] && set -x
program="${0##*/}"
if [ "$program" = "ruby" ]; then
for arg; do
case "$arg" in
-e* | -- ) break ;;
*/* )
if [ -f "$arg" ]; then
export RBENV_DIR="${arg%/*}"
break
fi
;;
esac
done
fi
export RBENV_ROOT="/Users/x-xxxxx/.rbenv"
exec "/Users/x-xxxxx/.rbenv/libexec/rbenv" exec "$program" "$@"
The same applies to bundled commands such as bundler
and gem
, and commands added by Gem.
$ which gem
/Users/x-xxxxx/.rbenv/shims/gem
$ which bundle
/Users/x-xxxxx/.rbenv/shims/bundle
$ which fluentd
/Users/x-xxxxx/.rbenv/shims/fluentd
And if you set up with rbenv init
normally,~ / .rbenv / shims /
will be added to the beginning of $ PATH and it will be used with the highest priority.
The ~ / .rbenv / shims /
script will try to execute the command of the same name in the ** currently in use version of Ruby **.
Therefore, if the command is not installed in ** the version of Ruby currently in use **, an error will occur;
fluentd
$ PATH
is searched from the beginning and found first ~ / .rbenv / shims / fluentd
is executed~ / .rbenv / shims / fluentd
searches the current directory for .rbenv-version to determine the Ruby version.flunetd
in that version of Ruby, but I can't find fluentd
(although it's installed in another version of Ruby)$ fluentd
rbenv: fluentd: command not found
The `fluentd' command exists in these Ruby versions:
2.6.3
Execute directly without going through ~ / .rbenv / shims / hoge
.
~/.rbenv/versions/2.6.1/bin/ruby
Add the path before ~ / .rbenv / shims.
Note that Ruby and Python have the ability to install commands in a directory directly under your home (not in the interpreter directory). It's a good idea to add that directory to your $ PATH.
$ export PYTHONUSERBASE=~/.local
$ pip3 install --user awscli
$ ls ~/.local/bin jupyter-notebook
$ ls ~/.local/bin/
jupyter
jupyter-bundlerextension
jupyter-console
jupyter-kernel
...
# ~/.bashrc
eval "$(pyenv init -)"
export PATH=$HOME/.local/bin:$PATH
In fact, you can build Ruby with rbenv install
without using rbenv init
.
For some people it may be enough to build.
Installing and using Ruby and Python commands globally is the source of trouble in the first place. Always use via pipenv or bundler.
Recommended Posts