Cannot change RVM gemset from shell script via `rvm gemset use`

好久不见. 提交于 2019-12-02 20:57:14

Had exactly the same problem, and here's the solution:

#!/bin/bash

# IMPORTANT: Source RVM as a function into local environment.
#            Otherwise switching gemsets won't work.
[ -s "$HOME/.rvm/scripts/rvm" ] && . "$HOME/.rvm/scripts/rvm"

# Enable shell debugging.
set -x

rvm 1.9.2@gemset_a
rvm gemdir
gem env gemdir

rvm 1.9.2@gemset_b
rvm gemdir
gem env gemdir

What I've found out is that your interactive shell has got rvm() and its helpers, whereas script's environment has not got them. rvm binary is executed instead, partially working and thus causing some confusion.

I ended up implementing the functionality I wanted as a function instead of a shell script.

function rvmrc {
  rvm gemset create $1
  rvm gemset use $1
  echo "rvm gemset use $1" > .rvmrc
  rvm rvmrc trust
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!