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

前端 未结 2 1984
挽巷
挽巷 2021-02-03 10:10

(See update at bottom)


I feel like I\'m missing something terribly obvious here, but I can\'t change gemsets from within a shell script. This minimal script demons

2条回答
  •  别那么骄傲
    2021-02-03 10:47

    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.

提交回复
热议问题