Ask A Question

Notifications

You’re not receiving notifications from this thread.

rbenv: bundle: command not found

Peter Boomsma asked in Servers

I'm trying to deploy my Rails app on my Digital Oceans VPS but I'm running into a error:

Running cap production deploy ends up with this error:

INFO[7cd03924] Running ~/.rbenv/bin/rbenv exec bundle install --binstubs /home/deploy/movieseat/shared/bin --path /home/deploy/movieseat/shared/bundle --without development test --deployment --quiet on 178.62.204.53
DEBUG[7cd03924] Command: cd /home/deploy/movieseat/releases/20141101124751 && ( RBENV_ROOT=~/.rbenv RBENV_VERSION=2.1.2 ~/.rbenv/bin/rbenv exec bundle install --binstubs /home/deploy/movieseat/shared/bin --path /home/deploy/movieseat/shared/bundle --without development test --deployment --quiet )a
DEBUG[7cd03924] rbenv: bundle: command not found

On my VPS I've done:

deploy@movieseat:/$ which bundle
/usr/local/bin/bundle

And:

deploy@movieseat:/$ rbenv which bundle
rbenv: bundle: command not found

I've also checked:

deploy@movieseat:/$ bundle -v
Bundler version 1.7.4

Does anyone know what's going wrong here?

Update
Added some commands.

deploy@movieseat:/$ rbenv version
2.1.2 (set by /home/deploy/.rbenv/version)
deploy@movieseat:/$ gem install bundler
ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /var/lib/gems/2.1.0 directory.
deploy@movieseat:/$ sudo gem install bundler
Successfully installed bundler-1.7.4
1 gem installed
Reply

It looks like your bundler on the machine is installed globally and not from rbenv. It might have been related to something you did previously. Basically you don't want to have to ever run sudo and if you do, you know something is configured wrong.

On my machine, I've got this (which is what you want, just with your user):

$ which ruby
/Users/chris/.rbenv/shims/ruby
$ which gem
/Users/chris/.rbenv/shims/gem
$ which bundle
/Users/chris/.rbenv/shims/bundle

It might be that you also don't have the gem command coming from rbenv. If you run gem install bundler and it doesn't use the rbenv gem command, it will use the system ruby and that's not going to be useful for you.

Reply

I've removed the droplet and started over. Hoping I did something wrong the first time. By machine, you mean the local or the VPS machine?

Reply

That was an example from my local machine but you will want the same results on your server user.

One thing you might double check is that rbenv is being loaded in your ~/.bashrc file properly. I think it is, but that could be why it isn't using the right gem/bundler commands.

Reply

Alright I've done all the steps again (also the guide doesn't really mention how to create the database.yml file) and again I get the same error.

rbenv: bundle: command not found

deploy@movieseat:~$ which gem
/home/deploy/.rbenv/shims/gem

deploy@movieseat:~$ which ruby
/home/deploy/.rbenv/shims/ruby

deploy@movieseat:~$ which gem
/home/deploy/.rbenv/shims/gem

deploy@movieseat:~$ which bundle
/usr/bin/bundle

If I run the which bundle command on my local machine I get

alucardu@alucardu-VirtualBox:~/sites/movieseat$ which bundle
/home/alucardu/.rbenv/shims/bundle

It seems that on my VPS my bundle path isn't correct. Is that the case? If so, how can I change that?

I have opend my vi ~/.bashrc file on the VPS, but I'm not sure what to check or edit.

At the bottom of the file I see

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

Your ~/.bashrc file looks correct. It seems everything is loading rbenv as expected.

I believe you should just be able to say gem install bundler on the VPS now because the gem command will come from rbenv and install bundler inside of rbenv appropriately. After that, your Capistrano deploys should work using that version of bundler.

Reply

Yup, just did a gem install bundler and it's working now.

The deploy doesn't get aborted now but when I go to my IP I only see the Welcome to nginx! Message. I did change this though:

root         /home/deploy/movieseat/current/public;

After restarting the nginx server I get a 403 Forbidden message on the site.

Reply

You should be able to find a file in the /var/log/nginx directory that will give you more details on what's going wrong. That looks right, but could be a handful of things that might cause the 403 Forbidden. There's usually an error.log file in there that will tell you if it can't find the directory or whatever else might be the case.

Reply

By the way, a question about the guide.

Find the following lines, and uncomment them:

# passenger_ruby /home/deploy/.rvm/wrappers/ruby-2.1.2/ruby; # If use use rvm, be sure to change the version number
# passenger_ruby /home/deploy/.rbenv/shims/ruby; # If you use rbenv

I don't have these two lines in my /etc/nginx/nginx.conf file. Should I add the following line?

passenger_ruby /home/deploy/.rvm/wrappers/ruby-2.1.2/ruby; # If use use rvm, be sure to change the version number

By the way, a few more things you might want to add or revise.

I had to add sudo apt-get install nodejs to my server, otherwise I got a ExecJS::RuntimeUnavailable error. Also how to create a database.yml file on the server would help.

Reply

Those two lines were more notes of mine that you should set passenger_ruby differently if you built Ruby from source vs rv vs rbenv. You just choose which line is relevant to you. In this case since you are using rbenv, you can ignore the lines that don't have .rbenv in the folder name.

The instructions for installing Node seem to have gone missing. I ran into that yesterday too while building up a new Droplet myself. Also need some sprucing up of the database.yml + secrets.yml.

For both of those, start deploying, let it fail, and when it says it couldn't find database.yml, just ssh into the server, visit /home/deploy/myapp/shared/config and type vim database.yml and write your production database config in their. You want to keep these files only on production for security reasons. You'll do the same thing with secrets.yml and put it in your linked_files in config/deploy.rb inside your app if you're using Rails 4.

Reply

Hm I've added the secrets.yml and database.yml to my deploy.rb, commited it to my git and added the files to my production server and then deployed. But I'm getting a:

An error occurred.

Sorry, the page you are looking for is currently unavailable.
Please try again later.

If you are the system administrator of this resource then you should check the error log for details.

Faithfully yours, nginx.

Message on my website.

Reply

I'd check your /var/log/nginx/error.log file for details.

Reply

Yes sorry. I've just opened another question. Might be easier to track for people who also have the problem, instead of searching through a endless topic.

Reply

Chris, is the installation of node really necessary? As long as you have therubyracer in your Gemfile you'll have a Javascript runtime in your Rails environment. I know therubyracer might be a bit more memory intensive than nodejs but it works, at least for me.

If you recommend nodejs over therubyracer can you update your setup guide with the proper installation instructions so others can benefit?

I've spun up multiple apps (mostly in 3.2.x branches) and used therubyracer in the Gemfile assets group without having node installed on the production server. And the app and deploys still work.

If you think I should be installing nodejs in production, please let me know your take on it.

Reply

I'm not really sure how much faster (if any) it is. I do think it's probably going to be faster and it used to be in the tutorial but I'm not sure when it went missing.

I need to experiment with a "submit an improvement" piece to the guides so that people like you can make improvements and I can quickly review the diff and merge them in.

Reply

I agree. I think a submit an improvement piece would be helpful. It would allow others to add value to the already valuable resources you provide. Plus a lot of us have edge cases which we could submit as "side notes".

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 87,563+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.