Can I execute gems from outside an rbenv environment?

落花浮王杯 提交于 2020-01-24 21:27:13

问题


I am able to install and execute a gem as follows:

rbenv install 2.4.1
rbenv local 2.4.1 # enter the environment
gem install fpm
fpm --version

I was expecting to be able to execute the gem from outside the environment too, something like:

rbenv local --unset # leave the environment
rbenv rehash # update shims
fpm --version

But instead I get:

rbenv: fpm: command not found

The `fpm' command exists in these Ruby versions:
  2.4.1

Have I misunderstood how rbenv shims work? Can I execute a gem from outside an rbenv environment?


回答1:


From the comments in your Github issue it seems you got the basic idea now; rbenv shims are nothing more than glorified shell scripts that tie a command to a particular currently active Ruby version.

But nothing prevents you from creating your own hard-coded shims. For example, let's say you want this global fpm command that is available outside any particular rbenv environment.

Here's a simple way to do it:

> rbenv local 2.4.1
> ln -s `rbenv which fpm` ~/.rbenv/bin/fpm24
> rbenv local --unset
> fpm24 --version
1.10.2

This will install a "shim" into ~/.rbenv/bin/fpm24 that is a hard-coded pointer to the 2.4.1 gem that rbenv has installed previously. Now this fpm24 command will work anywhere, as long as you have ~/.rbenv/bin in your PATH.



来源:https://stackoverflow.com/questions/51874821/can-i-execute-gems-from-outside-an-rbenv-environment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!