Whenever I do bundle install all of the gems get installed at
app_dir/vendor/bundle
path and consumes loads of disk space. I also tried installing gems where it should get installed i.e gemsets while development by this:
bundle install --no-deployement
but this isn't working for me and installeing gems at vendor/bundle. How can I make it to be installed globally for all applications or in ruby gemsets location ? I also tried removing .bundle/config but nothing changed.
I am using:
rvm version: 1.23.14
ruby version: 2.0.0-p247
rails 3.2.13
Here is my ~/.bash_profile:
export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
eval "$(rbenv init -)"
alias pg='pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log'
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function
My ~/.bashrc:
PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
Some other information that you might need:
aman#Amandeeps-MacBook-Pro ~/Projects/qe (develop)*$ which bundle
/Users/aman/.rvm/gems/ruby-2.0.0-p247#global/bin/bundle
aman#Amandeeps-MacBook-Pro ~/Projects/qe (develop)*$ rbenv which bundle
/Users/aman/.rbenv/versions/2.0.0-p247/bin/bundle
amandeep#Amandeeps-MacBook-Pro ~/Projects/qe (develop)*$ rbenv which ruby
/Users/aman/.rbenv/versions/2.0.0-p247/bin/ruby
aman#Amandeeps-MacBook-Pro ~/Projects/qe (develop)*$ rbenv gemset active
rbenv: NO such command `gemset'
aman#Amandeeps-MacBook-Pro ~/Projects/qe (develop)*$ which rails
/Users/aman/.rvm/gems/ruby-2.0.0-p247#global/bin/rails
I tried this also but didn't helped:
bundle install --system
and removing .bundle directory.
Please help me in installing gems in gemsets not vendor/bundle or a default place.
In your project folder you will have .bundle directory that holds configuration for bundler. try deleting that folder. it should reset the install path for your gems back to system-wide settings.
In the case you just want to edit the install path, opening .bundle/config with your favorite editor should show you the path to vendor/bundle. Removing that line will restore it to defaults without removing other configs you might have.
Also, another less frequent scenario is your system-wide settings being messed up. According to #NaoiseGolden:
I had to delete .bundle from my Home folder (rm -rf ~/.bundle). You can check out your configuration running bundle env
Try installing using
bundle install --system
I think initially the bundle install was run with --path flag and bundler now rememebers that confguration.
From the bundler man page
Some options are remembered between calls to bundle install, and by the Bundler runtime.
Subsequent calls to bundle install will install gems to the directory originally passed to --path. The Bundler runtime will look for gems in that location. You can revert this option by running bundle install --system.
EDIT: As mentioned in comments below, and also otherwise, this installs the gems system wide. In case you are using rvm etc to manage your environment for different apps, check #IuriG's answer mentioned above.
Use bundle env to view paths and bundle configuration
After this set bundle path to ~/.rvm/gems/ruby-2.0.0-p247 like this:
bundle install --path ~/.rvm/gems/ruby-2.0.0-p247
which is global and also you can use your own custom path.
Post this bundle install will never need path again and will always install all of your gems in that directory(~/.rvm/gems/ruby-2.0.0-p247 in my case) for that app not in app_folder/vendor/bundle
Try running bundle env. This will tell you where the path configuration is set.
First of all, acording to your info, it seems that you have installed both rvm and rbenv. Thats a very bad idea. You have to delete one of them (rbenv + bundler works like a charm for me, didnt try rvm).
In regard to your question check .bundle/config in your project, as all the configuration for bundle to that project lies there (if its still deleted, you can create a new one). You migh want to add this line (or change it, if its already there): BUNDLE_DISABLE_SHARED_GEMS: '0' for sharing gems, they go where your BUNDLE_PATH: is set (BUNDLE_PATH: vendor in my case).
For the global configuration file look in ~/.bundle/config
Also this man page could be of use: bundle config
To Install Gem in system wide avoiding path vendor/bundle, just run the following command in project directory
bundle install --system
$ brew install rbenv
$ rbenv install 2.7.6
$ rbenv install -l
2.7.6
$ rbenv global 2.7.6
$ gem install bundler
$ brew install rbenv-gemset
$ rbenv gemset create 2.7.6 mygemset
$ gem env home
/Users/myuser/.rbenv/versions/2.7.6/gemsets/mygemset
$ gem install rails
$ rails new myapp && cd myapp
$ bundle install
$ bundle show --paths
/Users/myuser/.rbenv/versions/2.7.6/gemsets/myapp/gems/actioncable-7.0.1
...
$ bundle config set --local path 'vendor/bundle'
$ file .bundle
$ .bundle: directory
$ cat .bundle/config
---
BUNDLE_PATH: "vendor/bundle"
$ bundle install # Note from time to time you will get some bizarre error "Could not find timeout-0.2.0 in any of the sources". Simply delete Gemfile.lock and run bundle install again.
$ bundle show --paths
/Users/myuser/myapp/vendor/bundle/ruby/2.7.0/gems/actioncable-7.0.4
$ bundle config set --local system 'true' # or you may want to delete BUNDLE_PATH: "vendor/bundle" from .bundle/config
$ rm -rf vendor/bundle
$ rbenv gemset active
mygemset global
$ bundle install
$ bundle show --paths
/Users/myuser/.rbenv/versions/2.7.6/gemsets/mygemset
All in all, when you install a ruby version manager, such as the preferable rbenv, then it will install gems according to its setup. However, if you update .config/bundle in your project to use 'vendor/bundle', then that's where 'bundle install' will install gems. Sometimes this is used to keep project specific gems, instead of using a gemset tool like rbenv-gemset. Other times it is required for deployment, such as deploying to AWS Lambda on its ruby2.7 runtime. The use of 'vendor/bundle' can be easily removed by removing its reference from .config/bundle as shown above. Once it is removed, it will default to the gem environment that exists globally, which in the above case is managed by rbenv.
Related
Your user account isn't allowed to install to the system RubyGems.
You can cancel this installation and run:
bundle install --path vendor/bundle
to install the gems into ./vendor/bundle/, or you can enter your password
and install the bundled gems to RubyGems using sudo.
Password:
If it says that you don't have the priviliges, then you just need to run it with sudo
sudo gem install bundler --no-rdoc --no-ri
but I really recommend installing rbenv or rvm, to have a better control of the ruby versions and with that you don't need password or sudo command to install the gems.
I will guide you to install rvm here, this is for personal preference, but you con install rvenb too with the same result.
before anything else, you have to remove completely the ruby version that you have installed on this moment and all the gems
gem uninstall --all # maybe you will need sudo here
sudo apt-get purge ruby
first install mpapis public key
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
then install rvm
\curl -sSL https://get.rvm.io | bash
then add to .bashrc
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # This loads RVM into a shell session.
add to .bash_profile
source ~/.profile
then you can install the ruby version that you want (i am using 2.3.0 here as an example, change for the version that you were working before on the app)
rvm install 2.3.0
with this you have installed ruby, I recommend to run this command if you would not use the documentation of gems in local
echo 'gem: --no-document' >> ~/.gemrc
then you can set the ruby version that you want to use, you have different options, select it manually everyime you open the terminal with
rvm use 2.3.0 # or the version that you want to use in that moment
or add to the gemfile the ruby version and rvm will select if for you everytime you make a cd to the path of the app adding this to your gemfile
source 'https://rubygems.org' # this is by default on your gemfile
ruby '2.3.0' # this is the line you need to add, change for the version that you want on he app
when you have the selected version of ruby, you have to install bundler gem, you need to run this just once by ruby version that you install
gem install bundle
then you can run bundle install on your app and will work like a charm.
With rvm you can have different versions of ruby on rails installed on your machine, an as I said, per version that you install you need to install the bundler gem once.
if you have differents version of ruby installed, I recommend that you add a default so if you haven't set the ruby version on the terminal in that session, it will take one by default, you can do it like this
rvm --default use 2.3.0
hope that this helps you to be clear.
I was reading the book Rails Way. And it discusses running "bundle package". This will store all the .gem files your app uses in vendor/cache. Running bundle install will prefer gems in vendor/cache to gems in other locations. I am using rvm, so I tested this with rvm:
rvm gemset create rent_prototype
rvm use 2.2.1#rent_prototype
gem install rails
rvm gemdir
/home/viggy/.rvm/gems/ruby-2.2.1#rentme_prototype
$ cd /home/viggy/.rvm/gems/ruby-2.2.1#rentme_prototype
$ ls -l devise-4.1.1
ls: cannot access devise-4.1.1: No such file or directory
Above I created a gemset with rvm and checked if the devise gem was installed, and it was not since it is not in Gemfile. Now I use bundle package:
$ cd -
$ bundle package
Updating files in vendor/cache
* rake-11.1.2.gem
* i18n-0.7.0.gem
* json-1.8.3.gem
...
$ cd vendor/cache
$ ls -l devise-4.1.1
ls: cannot access devise-4.1.1: No such file or directory
Of course, no devise gem in vendor/cache either.
Then I modify Gemfile and add:
gem 'devise'
Then I run bundle install.
Now I check where devise was installed:
$ bundle show devise
/home/viggy/.rvm/gems/ruby-2.2.1#rentme_prototype/gems/devise-4.1.1
$ cd vendor/cache
$ ls -l devise-4.1.1
ls: cannot access devise-4.1.1: No such file or directory
So when I install a gem, it installs in the rvm folder. It does not prefer vendor/cache to other locations. If that is the case, what is the purpose of "bundle package" when you are using rvm?
As per my comment. You didn't run package after adding devise to your gem file which is why it isn't in vendor/cache. Bundle install still needs to install the gems on your system.
From bundler website
The package command will copy the .gem files for your gems in the bundle into ./vendor/cache. Afterward, when you run bundle install,
Bundler will use the gems in the cache in preference to the ones on rubygems.org.
Additionally, if you then check that directory into your source
control repository, others who check out your source will be able to
install the bundle without having to download any additional gems.
The rvm gemset and bundler solve some of the same problems with which set of gems/versions are to be used / activated. With bundler now you don't need to use rvm gemsets , the gemfile handles it. But this wasn't always the case.
In order to fix something unrelated to this, I did a bundle install --path vendor/cache. Now every time I use bundle install, the gems are being installed into 'vendor/cache'. How can I revert this so that a bundle install installs the gems into the normal directory?
Update
bundle install --system makes no difference.
In project directory after this command bundle install --path vendor/cache bundler create config file in .bundle/config that contain bundler config:
---
BUNDLE_PATH: vendor/cache
BUNDLE_DISABLE_SHARED_GEMS: '1'
Delete or edit this file for you need.
--path options. Bundler will remember this value for future installs on this machine
You can specify this setting when installing via bundle install
/path/to/bundle. Bundler will remember where you installed the
dependencies to on a particular machine for future installs, loads,
setups, etc.
Also, you might want to check out ~/.bundle/config for the BUNDLE_PATH setting.
Following these steps from the bundler.io website solved the problem:
# remove project-specific settings
rm -rf .bundle/
# remove project-specific cached gems and repos
rm -rf vendor/cache/
# remove the saved resolve of the Gemfile
rm -rf Gemfile.lock
# uninstall the rubygems-bundler and open_gem gems
rvm gemset use global
# if using rvm
gem uninstall rubygems-bundler open_gem
# try to install one more time bundle install
This worked/was enough for me, when I discovered that the PATH was set in my project only.
Check the project's config file at: .bundle/config
Remove necessary files in your project:
rm .bundle/config
rm Gemfile.lock
rm -rf vendor
And then recreate Gemfile.lock:
bundle install
You need to set a path for your local app. It is vendor/cache in your case because you changed it. You can check the path (see path section):
bundle env
The solution is:
bundle install --path $BUNDLE_PATH
rm -rf vendor/
bundle install --path $GEM_HOME
I have rvm installed and have created .ruby-version specifying 1.9.3 and .ruby-gemset specifying my_project in my project directory. And when i run gem env gemdir it returns: /Users/danielfriisjensen/.rvm/gems/ruby-1.9.3-p392#my_project.
However, when I run bundle install, all the gems that I have specified in my gemfile are put in my_project/vendor/bundle/gems
Bundler was remembering the location from the first time I ran bundle install. Had to 'reset' bundler's memory be running rm -r .bundle/config
I've run "bundle install" on an existing Rails 3 app which has the gems in vendor/cache (I guess they were packed via "bundle package" before) and valid Gemfile and Gemfile.lock files.
What I saw is, it created a folder .bundle in my home dir.
I am using also RVM. When I tried "gem list", I didn't see any of the gems in vendor/cache installed.
Am I doing something wrong? Everywhere the bundler articles say, execute "bundle" or "bundle install" to install the gems in the Gemfile and Gemfile.lock files. Is the problem connected with the RVM usage?
Thanks for any advice.
If you give an argument to bundle install, it will keep installing the gems inside this directory, even if you rm -rf that directory and start from scratch with the pure bundle install, as noted in Emil's comment. This new directory is taken by default by bundler, and it even supersedes what you declare in the .rvmrc file.
To remove this constraint, simply edit the .bundle/config file and delete the file declaring BUNDLE_PATH, e.g.,
BUNDLE_PATH: /usr/local/lib/
Look in rvm env gemdir, also check what you've got set in .rvmrc in terms of a gemset. Do bundle install and it should get all the gems.
Check .bundle by doing $ cat .bundle to see its content , and check if it is copying the gems to vendor/ruby. This will only be the case if bundle install --path vendor/ruby was supplied (Ref).