27

Why zsh: command not found: bundle after gem install bundler?

I tried setting path=( /usr/local/lib/ruby/gems/2.2/gems/ ~/bin /bin /sbin /usr/bin /usr/sbin /usr/local/bin /usr/local/sbin ) in /etc/zshrc and source /etc/zshrc to no avail.

root@dev:/home/dev# gem install bundler
Successfully installed bundler-1.7.12
Parsing documentation for bundler-1.7.12
Done installing documentation for bundler after 10 seconds
1 gem installed

root@dev:/home/dev# bundle
zsh: command not found: bundle

root@dev:/home/dev# uname -a
OpenBSD dev.my.domain 5.7 GENERIC#748 amd64

root@dev:/home/dev# gem environment
RubyGems Environment:
  - RUBYGEMS VERSION: 2.4.5
  - RUBY VERSION: 2.2.0 (2014-12-25 patchlevel 0) [x86_64-openbsd]
  - INSTALLATION DIRECTORY: /usr/local/lib/ruby/gems/2.2
  - RUBY EXECUTABLE: /usr/local/bin/ruby22
  - EXECUTABLE DIRECTORY: /usr/local/bin
  - SPEC CACHE DIRECTORY: /root/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /etc
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-openbsd
  - GEM PATHS:
     - /usr/local/lib/ruby/gems/2.2
     - /usr/local/lib/ruby/gems/2.2/gems/
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - /usr/local/lib/ruby/gems/2.2/gems/
     - /root/bin
     - /bin
     - /sbin
     - /usr/bin
     - /usr/sbin
     - /usr/local/bin
     - /usr/local/sbin
Mark Boulder
  • 13,577
  • 12
  • 48
  • 78

5 Answers5

36

I had the same issue using zsh and this fixed it:

$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zshenv
$ echo 'eval "$(rbenv init -)"' >> ~/.zshenv
$ echo 'source $HOME/.zshenv' >> ~/.zshrc
$ exec $SHELL
Hany Moh.
  • 949
  • 1
  • 11
  • 11
Ricardo Rojas
  • 469
  • 4
  • 3
28

You seem to be after installing bundler system-wide. To do this, you need to pass --no-user-install flag to gem and execute it with sudo:

sudo gem install bundler --no-user-install

After this, you should see bundle in /usr/bin/ just fine:

$ ls /usr/bin/bundle
/usr/bin/bundle*
rr-
  • 14,303
  • 6
  • 45
  • 67
11

You can check the directory in which Rubygems will install gem executables with gem environment.

One of the first points should be EXECUTABLE DIRECTORY. Make sure this directory is in your $PATH (listed as SHELL PATH btw)

mhutter
  • 2,800
  • 22
  • 30
7

You shound run the below command after installed bundler:

rbenv rehash
Yoyo
  • 165
  • 2
  • 4
2

Also just ran into the same error when setting up jekyll. My gem env shows GEM PATHS as follows:

- GEM PATHS:
    - /usr/local/lib/ruby/gems/2.5.0

The content of this directory looks like this:

bin/            cache/          extensions/     specifications/
build_info/     doc/            gems/

Inside bin, I see both jekyll and bundle:

$cd /usr/local/lib/ruby/gems/2.5.0/bin/
$ls
bundle        jekyll        listen        safe_yaml     sass-convert
bundler       kramdown      rougify       sass          scss

If you find similar paths and files as I do, any one of the following approaches should work:

  • Append the full path /usr/local/lib/ruby/gems/2.5.0/bin/ to PATH via:

    export PATH="/usr/local/lib/ruby/gems/2.5.0/bin/:$PATH"
    
  • Make symbolic links in /usr/local/bin via:

    $cd /usr/local/bin
    $ln -sf /usr/local/lib/ruby/gems/2.5.0/bin/bundle .
    $ln -sf /usr/local/lib/ruby/gems/2.5.0/bin/jekyll .
    
  • Set up aliases in .zshrc (or .bashrc and alike):

    alias jekyll="/usr/local/lib/ruby/gems/2.5.0/bin/jekyll"
    alias bundle="/usr/local/lib/ruby/gems/2.5.0/bin/bundle"
    

In general, I felt all this path blindness makes the experience of setting up a jekyll site bumpier than expected:( If others have a set of steps that just work (without such needs for troubleshooting), please comment :)

Shan Dou
  • 3,088
  • 1
  • 20
  • 18