Capistrano, Rbenv, bundle: command not found

After running

cap production deploy:restart

Our remote Puma log would show the following:

-su: bundle: command not found

However, this was an active production server, so the bundler gem existed. After logging in and attempting to run a simple command, such as:

bundle exec rails console

The console would output the following:

The program 'bundle' is currently not installed. You can install it by typing:
sudo apt-get install bundler

So, we looked at the PATH var to ensure RBENV was properly configured

printenv PATH

And it was.

If this is your problem (there should be rbenv paths specified here), then edit your ~/.bashrc or ~/.profile or whatever you’re using and add the following lines at the bottom:

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

This will most likely solve the problem you’re noticing.

However, in our case, this was not the issue. RBENV was properly configured, the environment variables were set, and bundler was definitely installed. Next, we figured we’d run

rbenv rehash

Just in case something went awry on that front, but we encountered this error:

rbenv: cannot rehash: /home/deployer/.rbenv/shims/.rbenv-shim exists

So, we're getting somewhere. This file only exists to avoid colliding rehashes, however, I knew no other rehash's were in progress, so this file must have not be cleaned out during the last rehash for some reason, so we ran:

rm ~/.rbenv/shims/.rbenv-shim

And re-ran

rbenv rehash

And everything went back to normal.

Leave a Reply

Your email address will not be published. Required fields are marked *