简体   繁体   English

Rbenv无法正确重新哈希并填充

[英]Rbenv not rehashing correctly and making shims

The bottom line is, rbenv isn't making shims. 底线是,rbenv不会产生垫片。 I've exhausted ideas of what could be the problem. 我已经精疲力尽了可能是什么问题的想法。 After a few days of banging my head against a wall to fix but no avail, I think it's time to ask for help. 在将我的头撞在墙上修复了几天但无济于事之后,我认为是时候寻求帮助了。

I'm attempting to make the switch from RVM to rbenv, so that could obviously be a factor here. 我正在尝试从RVM切换到rbenv,因此显然这可能是一个因素。 Any ideas/help would be great. 任何想法/帮助都很好。

Here's what happens: 这是发生了什么:

[09:38] ~ $ gem install pry
Fetching: pry-0.10.2.gem (100%)
Successfully installed pry-0.10.2
1 gem installed

[09:39] ~ $ rbenv rehash

[09:40] ~ $ pry
bash: pry: command not found

[09:40] ~ $ rbenv which pry
rbenv: pry: command not found

[09:40] ~ $ which pry
which: no pry in (/home/caveman/.rbenv/plugins/ruby-build/bin:/home/caveman/.rbenv/shims:/home/caveman/.rbenv/bin:/home/caveman/.rbenv/shims:/home/caveman/.rbenv/bin:/home/caveman/.rbenv/plugins/ruby-build/bin:/home/caveman/.rbenv/shims:/home/caveman/.rbenv/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl)

[09:41] ~ $ ~/.gem/ruby/2.2.0/bin/pry 
[1] pry(main)> puts "I'm working now"
I'm working now

[09:43] ~ $ gem list | grep pry
pry (0.10.2)

Here's my gem environment: 这是我的宝石环境:

[09:44] ~ $ gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 2.4.8
  - RUBY VERSION: 2.2.0 (2014-12-25 patchlevel 0) [x86_64-linux]
  - INSTALLATION DIRECTORY: /home/caveman/.gem/ruby/2.2.0
  - RUBY EXECUTABLE: /home/caveman/.rbenv/versions/2.2.0/bin/ruby
  - EXECUTABLE DIRECTORY: /home/caveman/.gem/ruby/2.2.0/bin
  - SPEC CACHE DIRECTORY: /home/caveman/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY:  /home/caveman/.rbenv/versions/2.2.0/etc
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-linux
  - GEM PATHS:
     - /home/caveman/.gem/ruby/2.2.0
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
     - "gem" => "--no-document"
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - /home/caveman/.rbenv/versions/2.2.0/bin
     - /usr/lib/rbenv/libexec
     - /home/caveman/.rbenv/plugins/ruby-build/bin
     - /home/caveman/.rbenv/shims
     - /home/caveman/.rbenv/bin
     - /home/caveman/.rbenv/shims
     - /home/caveman/.rbenv/bin
     - /home/caveman/.rbenv/plugins/ruby-build/bin
     - /home/caveman/.rbenv/shims
     - /home/caveman/.rbenv/bin
     - /usr/local/sbin
     - /usr/local/bin
     - /usr/bin
     - /usr/lib/jvm/default/bin
     - /usr/bin/site_perl
     - /usr/bin/vendor_perl
     - /usr/bin/core_perl

Here is my .bashrc file: 这是我的.bashrc文件:

[09:46] ~ $ cat .bashrc
# If not running interactively, don't do anything
[[ $- != *i* ]] && return

# If I don't set this, gem reverts back to nonexistent RVM directory.
export GEM_HOME=$(ruby -e 'print Gem.user_dir')
export GEM_PATH=$(ruby -e 'print Gem.user_dir')

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

And here is .bash_profile: 这是.bash_profile:

[09:52] ~ $ cat .bash_profile 

[[ -f ~/.bashrc ]] && . ~/.bashrc

source ~/.profile

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

I suspect your .bashrc is the problem. 我怀疑您的.bashrc是问题。 It shouldn't contain: 它不应包含:

# If I don't set this, gem reverts back to nonexistent RVM directory.
export GEM_HOME=$(ruby -e 'print Gem.user_dir')
export GEM_PATH=$(ruby -e 'print Gem.user_dir')

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

Of my ~/.bashrc, ~/.profile and ~/.bash_profile files, only the last has configuration for rbenv: 在我的〜/ .bashrc,〜/ .profile和〜/ .bash_profile文件中,只有最后一个具有rbenv的配置:

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

That was created when I installed rbenv, which matches the settings for my other systems where I use rbenv, including some that previously had RVM installed. 那是我安装rbenv时创建的,它与我使用rbenv的其他系统(包括以前安装了RVM的其他系统)的设置匹配。

Your double PATH assignments look like the culprit. 您的双重PATH分配看起来像元凶。 Compare the PATH for my system to yours, which is listed by gem env : 将我的系统的PATH与您的系统进行比较, gem env列出了您的系统:

 - /Users/ttm/.rbenv/versions/2.2.3/bin
 - /Users/ttm/.rbenv/libexec
 - /Users/ttm/.rbenv/plugins/ruby-build/bin
 - /Users/ttm/.rbenv/plugins/rbenv-whatis/bin
 - /Users/ttm/.rbenv/plugins/rbenv-vars/bin
 - /Users/ttm/.rbenv/plugins/rbenv-use/bin
 - /Users/ttm/.rbenv/plugins/rbenv-update/bin
 - /Users/ttm/.rbenv/plugins/rbenv-update-rubies/bin
 - /Users/ttm/.rbenv/plugins/rbenv-gemset/bin
 - /Users/ttm/.rbenv/plugins/rbenv-env/bin
 - /Users/ttm/.rbenv/plugins/rbenv-each/bin
 - /Users/ttm/.rbenv/shims
 - /Users/ttm/.rbenv/bin

Similarly, my which pry returns: 同样,我的which pry返回:

/Users/ttm/.rbenv/shims/pry

Using rbenv's env plugin shows: 使用rbenv的env插件显示:

RBENV_VERSION=2.2.3
RBENV_GEMSET_ALREADY=yes
RBENV_ROOT=/Users/ttm/.rbenv
RBENV_HOOK_PATH=:/Users/ttm/.rbenv/rbenv.d:/usr/local/etc/rbenv.d:/etc/rbenv.d:/usr/lib/rbenv/hooks:/Users/ttm/.rbenv/plugins/rbenv-default-gems/etc/rbenv.d:/Users/ttm/.rbenv/plugins/rbenv-gemset/etc/rbenv.d:/Users/ttm/.rbenv/plugins/rbenv-readline/etc/rbenv.d:/Users/ttm/.rbenv/plugins/rbenv-vars/etc/rbenv.d
PATH=/Users/ttm/.rbenv/versions/2.2.3/bin:/Users/ttm/.rbenv/libexec:/Users/ttm/.rbenv/plugins/ruby-build/bin:/Users/ttm/.rbenv/plugins/rbenv-whatis/bin:/Users/ttm/.rbenv/plugins/rbenv-vars/bin:/Users/ttm/.rbenv/plugins/rbenv-use/bin:/Users/ttm/.rbenv/plugins/rbenv-update/bin:/Users/ttm/.rbenv/plugins/rbenv-update-rubies/bin:/Users/ttm/.rbenv/plugins/rbenv-gemset/bin:/Users/ttm/.rbenv/plugins/rbenv-env/bin:/Users/ttm/.rbenv/plugins/rbenv-each/bin:/Users/ttm/.rbenv/shims:/Users/ttm/.rbenv/bin:/Users/ttm/.pyenv/shims:/Users/ttm/.pyenv/bin:/Users/ttm/perl5/perlbrew/bin:/Users/ttm/perl5/perlbrew/perls/perl-5.18.1/bin:/Users/ttm/bin:/usr/local/mysql-5.6.16-osx10.7-x86_64/bin:/Users/ttm/libsmi/bin:/usr/local/git/bin:/usr/local/bin:/Library/PostgreSQL/9.2/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/git/bin
RBENV_SHELL=bash
RBENV_DIR=/Users/ttm
RUBYLIB=/Users/ttm/.rbenv/rbenv.d/exec/gem-rehash:

I'd do these steps: 我将执行以下步骤:

  1. Modify ~/.bashrc, and the others, removing any lines referring to rbenv and/or RVM. 修改〜/ .bashrc等,删除所有引用rbenv和/或RVM的行。 RVM uses all three init files, plus .zshrc, whereas rbenv only seems to touch ~/.bash_profile. RVM使用所有三个init文件以及.zshrc,而rbenv似乎只涉及〜/ .bash_profile。
  2. Close the terminal session. 关闭终端会话。 Reopen it. 重新打开它。
  3. Confirm the PATH is free from all references to RVM and rbenv. 确认PATH不含对RVM和rbenv的所有引用。
  4. Reinstall rbenv following the Installation instructions. 按照安装说明重新安装rbenv。 It won't override the current installation, but instead will reinstall its changes to ~/.bash_profile. 它不会覆盖当前安装,而是会将其更改重新安装到〜/ .bash_profile。
  5. Close the terminal session again and reopen it. 再次关闭终端会话,然后重新打开。

rbenv should now be initialized correctly. 现在应该正确初始化rbenv。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM