我可以在rbenv环境之外执行gems吗? [英] Can I execute gems from outside an rbenv environment?

查看:97
本文介绍了我可以在rbenv环境之外执行gems吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够按照以下步骤安装和执行gem:

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

我还希望能够从环境外部执行gem,例如:

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

但是我得到了:

rbenv: fpm: command not found

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

我是否误解了rbenv垫片的工作原理?我可以在rbenv环境之外执行宝石吗?

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

推荐答案

从您的Github问题中的评论看来,您现在已经掌握了基本思想; rbenv垫片只不过是美化的shell脚本,这些脚本将命令绑定到特定的当前处于活动状态的Ruby版本.

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.

但是没有什么可以阻止您创建自己的硬编码垫片.例如,假设您希望此全局fpm命令在任何特定的rbenv环境之外都可用.

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.

这是一种简单的方法:

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

这会将一个"shim"安装到~/.rbenv/bin/fpm24中,它是指向rbenv先前已安装的2.4.1 gem的硬编码指针.现在,只要您在PATH中包含~/.rbenv/bin,此fpm24命令就可以在任何地方使用.

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.

这篇关于我可以在rbenv环境之外执行gems吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆