如何使用rbenv配置bash环境?

时间:2016-10-09 02:59:51

标签: ruby ubuntu rbenv

我实际上是在一台不是最新的服务器上维护一个Ruby应用程序(Ubuntu 10.04.2 LTS)。 RVM是全球安装的,我试图在我的主目录中本地获取最近的ruby版本,但没有任何成功。现在我正在尝试使用rbenv。

我刚刚安装了Ruby 2.3.1和rbenv& ruby-build(作为rbenv插件)。 安装工作完美,但不是用法。

安装(简单部分):

$ rbenv install 2.3.1
Downloading ruby-2.3.1.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.1.tar.bz2
Installing ruby-2.3.1...
Installed ruby-2.3.1 to /home/atlantic/.rbenv/versions/2.3.1

我已经像他们说的那样更新了.bash_profile:

$ cat .bash_profile 
# include .bashrc if it exists
if [ -f ~/.bashrc ]; then
    . ~/.bashrc
fi

export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"

但是当我想检查环境参数的环境时,请使用全局路径(如GEM PATHS,EXECUTABLE DIRECTORY,INSTALLATION DIRECTORY,...):

$ gem env 
RubyGems Environment:
  - RUBYGEMS VERSION: 2.5.1
  - RUBY VERSION: 2.3.1 (2016-04-26 patchlevel 112) [x86_64-linux]
  - INSTALLATION DIRECTORY: /usr/local/rvm/gems/ruby-2.0.0-p247
  - USER INSTALLATION DIRECTORY: /home/atlantic/.gem/ruby/2.3.0
  - RUBY EXECUTABLE: /home/atlantic/.rbenv/versions/2.3.1/bin/ruby
  - EXECUTABLE DIRECTORY: /usr/local/rvm/gems/ruby-2.0.0-p247/bin
  - SPEC CACHE DIRECTORY: /home/atlantic/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /home/atlantic/.rbenv/versions/2.3.1/etc
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-linux
  - GEM PATHS:
     - /usr/local/rvm/gems/ruby-2.0.0-p247
     - /usr/local/rvm/gems/ruby-2.0.0-p247@global
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - /home/atlantic/.rbenv/versions/2.3.1/bin
     - /home/atlantic/.rbenv/libexec
     - /home/atlantic/.rbenv/plugins/ruby-build/bin
     - /home/atlantic/.rbenv/shims
     - /home/atlantic/.rbenv/bin
     - /usr/local/rvm/gems/ruby-2.0.0-p247/bin
     - /usr/local/rvm/gems/ruby-2.0.0-p247@global/bin
     - /usr/local/rvm/rubies/ruby-2.0.0-p247/bin
     - /usr/local/rvm/bin
     - /usr/local/sbin
     - /usr/local/bin
     - /usr/sbin
     - /usr/bin
     - /sbin
     - /bin
     - /usr/games

当我查看env时,有许多针对全局ruby安装的env变量。我不知道我们在哪里设置这些变量,但这不是我想要的价值:

$ env |grep -i ruby
GEM_HOME=/usr/local/rvm/gems/ruby-2.0.0-p247
IRBRC=/usr/local/rvm/rubies/ruby-2.0.0-p247/.irbrc
MY_RUBY_HOME=/usr/local/rvm/rubies/ruby-2.0.0-p247
PATH=/home/atlantic/.rbenv/shims:/home/atlantic/.rbenv/bin:/usr/local/rvm/gems/ruby-2.0.0-p247/bin:/usr/local/rvm/gems/ruby-2.0.0-p247@global/bin:/usr/local/rvm/rubies/ruby-2.0.0-p247/bin:/usr/local/rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
GEM_PATH=/usr/local/rvm/gems/ruby-2.0.0-p247:/usr/local/rvm/gems/ruby-2.0.0-p247@global
RUBY_VERSION=ruby-2.0.0-p247

rbenv ruby​​安装永远不会出现在这些变量上。 我是否有一个命令(如rbenv init-env-variables)来正确配置我的ruby env?

感谢您的支持, 大卫

2 个答案:

答案 0 :(得分:0)

运行rvm implode --force

这将删除rvm /目录及其中构建的所有rubies。

运行gem uninstall rvm

检查.bashrc.profile.bash_profile并删除对RVM的任何引用。应该看起来像这样

[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function

从以下位置删除RVM

rm -rf /usr/local/rvm
sudo rm /etc/profile.d/rvm.sh
sudo rm /etc/rvmrc

/etc/profile中删除这些行(如果存在)

source /etc/profile.d/sm.sh
source /etc/profile.d/rvm.sh

使用source重新加载终端并重新启动rbenv安装过程。

答案 1 :(得分:0)

我手动更新文件.bash_profile以取消设置与rvm一起使用的所有变量环境,现在它可以完美运行:

$ cat /home/atlantic/.bash_profile 
# include .bashrc if it exists
if [ -f ~/.bashrc ]; then
    . ~/.bashrc
fi

unset rvm_bin_path
unset GEM_HOME
unset IRBRC
unset MY_RUBY_HOME
unset rvm_path
unset rvm_prefix
unset rvm_version
unset GEM_PATH
unset RUBY_VERSION


export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"

结果:

$ gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 2.5.1
  - RUBY VERSION: 2.3.1 (2016-04-26 patchlevel 112) [x86_64-linux]
  - INSTALLATION DIRECTORY: /home/atlantic/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0
  - USER INSTALLATION DIRECTORY: /home/atlantic/.gem/ruby/2.3.0
  - RUBY EXECUTABLE: /home/atlantic/.rbenv/versions/2.3.1/bin/ruby
  - EXECUTABLE DIRECTORY: /home/atlantic/.rbenv/versions/2.3.1/bin
  - SPEC CACHE DIRECTORY: /home/atlantic/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /home/atlantic/.rbenv/versions/2.3.1/etc
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-linux
  - GEM PATHS:
     - /home/atlantic/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0
     - /home/atlantic/.gem/ruby/2.3.0
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - /home/atlantic/.rbenv/versions/2.3.1/bin
     - /home/atlantic/.rbenv/libexec
     - /home/atlantic/.rbenv/plugins/ruby-build/bin
     - /home/atlantic/.rbenv/shims
     - /home/atlantic/.rbenv/bin
     - /usr/local/rvm/gems/ruby-2.0.0-p247/bin
     - /usr/local/rvm/gems/ruby-2.0.0-p247@global/bin
     - /usr/local/rvm/rubies/ruby-2.0.0-p247/bin
     - /usr/local/rvm/bin
     - /usr/local/sbin
     - /usr/local/bin
     - /usr/sbin
     - /usr/bin
     - /sbin
     - /bin
     - /usr/games

感谢您的建议和帮助。 大卫。