How do I ensure ruby gems are installed in right place to be executed by bundler?

随声附和 提交于 2019-11-29 11:33:17

From a clean start

You do not have to do anything apart from the plain steps stated on the Bundler home page:

  • Do NOT use sudo bundle ...
  • Do NOT change anything to your PATH
  • Do not touch any ~/.file

  • Copy require 'bundler/setup' at the top of your first application file

  • DO use bundle exec in front of all your Bundler-managed "binaries"

Everything just works using the nice defaults for a developer workstation. When you want to go further like running multiples Rubies side by side or deploying to prod or are fed up with typing bundle exec (which you should alias to bex using alias bex='bundle exec') you can then Read The Full Manual, type bundle install --binstubs and install one of the Rubymongers (RBEnv, RVM).

In your specific situation

I would restart from scratch:

  • uninstall RBEnv (rm -rf ~/.rbenv and delete rbenv mentions in grep rbenv ~/.bashrc ~/.bash_profile ~/.zshrc /etc/profile /etc/profile.d/*)
  • uninstall Bundler

Use rbenv-gemset. It works great and meets all your requirements. I have been using it for 2 years and have not had any problems. No issues with Heroku.

Here's my process for setting up a new Ruby project:

1. Create directory (or Rails app in new directory)
2. cd directory
3. Set ruby version: Use 2.1.0 or another version 
   rbenv local 2.1.0
4. Set gemset: replace app-name with the name of the app
   echo app-name > .rbenv-gemsets
5. Check gemset. Should be app-name global:
   rbenv gemset active
6. rbenv rehash
7. Create Gemfile
8. gem install bundler
9. bundle

When it does not work as expected, do rbenv rehash.

You should never need to install gems using sudo.

Regarding your shell, that could be causing problems. If a regular terminal doesn't work then there is probably another issue.

Since the issue seems related to your shell and PATH, here's my .bash_profile

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

You may want to try replacing your .bash_profile with the above, or create a new user and see if the issue disappears.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!