I'm using a few gems for interactivity with my database and to provide easy pagination. After deploying my application on my server, it'll automatically execute bundle install to install those gems if they aren't installed yet. This is helpful when I deploy a codebase update including a new gem.
However, there's one gem (will_paginate) I've made a little change to (so that it always shows on what page you are, no matter the total number of pages).
Therefore, I used bundle install --local --path vendor at my local machine (OS X Lion) so that I can easily edit them (at per-app base, instead of system-wide).
Because of dependency problems, I cannot 'just' copy the vendor-folder to my web server. Therefore, I decided to add another rule to my .gitignore-file:
vendor
Because this caused my customized will_paginate-gem not to get uploaded, I executed another command:
git add -f vendor/ruby/1.8/gems/will_paginate
Now, when I push, the only gem in the vendor folder at my web server is will_paginate, which is great.
However, it doesn't get loaded, since it isn't in the bundle path.
I already tried to create a file called .bundle/config and add the following in it:
---
BUNDLE_PATH: vendor
I also tried adding BUNDLE_DISABLE_SHARED_GEMS: "0", but using this, bundle check says it's missing the shared gems.
My question is, how can I add a bundle path vendor, and fallback on the system-wide gem-path.
Related
I ran bundle --without development on my machine and now I want to include the dependencies in my development group in my local rails app.
I ran bundle thinking it would including everything again including development, but I receive this message Gems in the groups development were not installed still. Can you tell me the option I need to pass into the bundle command to get the development gems back into my application? I tried running bundle --include development with no luck.
Can you also tell me where you found the option (if thats the solution)? I can't seem to locate a list of bundle options.
If you run
bundle help install
then both the with and without options are documented. Note that without is listed as being a "remembered option" i.e. it is persisted for subsequent calls.
Remembered options are stored in .bundle/config at the root of the project. You can either edit this file directly or view them using
bundle config
Which will also take into account user level configuration or environment variables that affect bundler
I was surprised to confirm this behavior. It seems like the without --development flag is saved, so even if you rm Gemfile.lock, running bundle again will not install the development group. bundle update also doesn't work.
You were close, though, with bundle --include development.
What works is bundle --with development. You don't need to delete your Gemfile.lock before doing this.
I am new to rails and am learning about bundler. I understand that bundle install installs all the gems specified in the gemfile but where does it install them to?
Does it install them on my computer permanently so that they can be used by any future project?
If so doesnt this mean my computer gets filled with random gem versions and gem installs that I needed for one example project but may never use again?
By default, bundle install is going to install at the root level so all users on a computer could have access to the gems. So 'yes' it is permanent (at least not tied to your application, you can remove them whenever you want).
Take a look at the man pages for bundler. In here, you'll notice that you can specify to install to a local directory.
Install your dependencies, even gems that are already installed to your system gems, to a location other than your system's gem
repository. In this case, install them to vendor/bundle.
$ bundle install --path vendor/bundle
Further bundle commands or calls to Bundler.setup or Bundler.require
will remember this location.
This will let you install the gems to a location inside your application. So when you delete the example app, you also delete the associated gems.
Also, if you would like to see where a specific gem is installed (say you want to look at its source code), type bundle show <gemname>. This will spit out the path to that gem.
The short answer is 'yes'. The longer answer is that there are some technologies which will reduce or eliminate the problems associated with this effect.
If you install 'RVM':
https://rvm.io/
this will allow you to install multiple versions of Ruby and create individual 'gemsets'. As you enter the directory that contains your project, the ruby version and gemset settings are automatically picked up and the active Ruby version will change. This way you can keep gems separate between projects - and use several Ruby versions at once, including JRuby and other esoteric versions.
To find out where gems are stored, type:
gem environment
into your command line and look for the INSTALLATION_DIRECTORY entry in the response.
I'm very new to ruby on rails which is why I'm trying to get a basic understanding of how it works. I have just created my very first rails app which is located in my dropbox folder. As I reformatted my computer two questions arise.
1) I had to do bundle install again in order to launch my local server. Why is that?
2) Also, prior to reformatting, I did cmd+p in sublime to search for files. However, files within gems didn't show in the results - now they do.
Everything works just as it did before I reformatted, I'm just trying to understand those two elements.
Thanks in advance!
Gem are not stored within your project.
If you are using RVM to maintain ruby version then gems are stored within that rvm folder.
As you have formatted your PC, it has removed gem folder from your system.
So, it is requesting for "bundle install".
This command will installing gems listed in applications GEMFILE.
If gem are already present in gem folder then it just use it for your project.
Gems that you require in your project are not stored in your project they are normally stored in a gems folder within your ruby install folder which would be on your local drive.
If for instance your start a new rails project you would see when you run bundle install every gem it checks for would already be installed becasue it's looking into the local gems folder.
So here's my problem:
I have a project and I am trying to install Gems locally to that project. For example if I install devise from the Gemfile and then run a bundle install it won't put any of the controllers in the controllers directory of the project. Instead I have to hunt through the RVM directories to get that particular gem's controllers, copy them to my project and then start writing my project from there.
Any suggestions?
I think the comment above answered your question - when you add a gem like Devise to your app, it doesn't generally drop code directly into your application. Sometimes it provides a generator which will install some parts of it, but mostly it alters config files so that the code in the gem gets pulled into your app when it starts.
You can ask bundler to install gems in the "vendor" subdirectory of your app, instead of in the main RVM/Ruby location, with the --path option. But you usually only want to do that for production deployment, not development.
It seems that on development machines (like on the Macbook), if we use bundle install --deployment, all the gems will be installed into the vendor/bundle folder and it just use more disk space if we have multiple Rails 3 projects (some project just for testing Rails 3). If it is not --deployment, then the gems will be in the "generic" folder instead of inside the project folder, and so can be shared across projects. Is this true?
Another thing is, do we need to add all files under vendor/bundle to our repository and push it? It seems that if we do it, we just jam up the repo, because if we don't, all the appropriate gems will be installed by bundle install using all the gems specified in Gemfile.lock anyway. (The Gemfile.lock is a small file in the repo). Is this true too?
Yes! True.
When you use the --deployment flag, Bundler makes sure that every gem you need is vendored i.e. they are copied to a predetermined place your application's folder structure (which happens to be vendor/bundle in Rails by convention) This is good for two things.
First if you have limited permissions that prevent you from installing gems in your deployment machine, then let you have all the gems needed within your app.
Second, if you want to hack away at the actual code in the gems, you can do so on your vendored copies without affecting the system gems. The changes you make will only affect the application you're working on.
This vendoring approach used to have another use, that is making sure that you are using the specific version of a gem, and your application would keep working even if the system gems were upgraded to a higher version that would break your app. However, Bundler itself made this use case mostly obsolete, as it automated the installation and referencing of specific versions of gems.
And yes, vendoring would bloat your app's code. Gemfile.lock is just a list of the required gems. If you vendor your gems, they get copied into your app with all their might.
So, I recommend you don't vendor your gems (that also means don't use the --deployment flag) unless you have one of the reasons above.
I think vendor/bundle, will not affect repo as long as the repo allows you to ignore files.
One can ignore it (adding the path to .gitignore if you are using git) and on server have a symlink to share the gems with multiple revisions.