Why 'bundle install' need these files to be pre-installed? - ruby

Here's what I tried:
gem install testgen
success
gem install bundlesuccess
go to project root created using testgen
bundle install this failed and asked to install gem install i18n -v '0.6.11' So I added it in gemfile this way gem 'i18n', '>=0.6.11' and tried bundle install again but it gave same error again. So I had to install it manually without using bundle install
Once this is completed it asked for many other files.
Question is: If I had to install gems manually one by one what's the use of bundle install then?
and
Why it was not installing the required gem when it is specified in Gemfile?

The command bundle install goes through every gem in the Gemfile and installs it, along with all dependencies.
An error like yours means that one of the gems, or one of its dependencies, failed to install. The Gemfile is already referencing the failing gem; you don't need to reference it again. Instead, try it from the command line:
gem install i18n -v '0.6.11'
This might fail, but the error will be more useful. This process isn't 'installing gems manually', it is solving problems your computer is raising with certain pieces of software. Bundler can't work through every problem on every kind of machine on its own.
Check out http://bundler.io/, it has some great docs that should help clarify.

Related

Bundle install fails, Gem install succeeds

When trying to bundle install on a Gemfile that contained only the GitHub Pages gem and nothing else, on Ubuntu 18.04, I got error messages telling me to try installing eventmachine using gem install. That always succeeds, but bundle install still fails. How can I get bundler to see that the gem is installed?
I fixed this after many hours of struggle, by noticing that on the GitHub Pages repo there's a note that says
Important: Make sure you have Bundler > v1.14 by running gem update bundler in your terminal before following the next steps.
I have no idea why this mattered but I removed my ruby packages from Ubuntu and reinstalled them, then installed bundler with rubygems, which gave me a newer version:
sudo apt-get remove ruby
sudo apt-get install ruby ruby-dev
sudo gem install bundler
bundler --version
If anyone knows why I needed that version of bundler, or how I should have diagnosed this faster, I'd be interested to hear it. I'm not new to programming but I'm new to Ruby.
From my understanding it might be the gem you are trying to install requires a specific feature provided by bundler. If you check the change log of bundler there is some changes related to install github based gems on how to correctly read the user git settings. So I think that might be where the problem is from.

Bundler install custom path issue

gem env shows
GEM PATHS:
/usr/local/share/gems
I would like to use bundle install --deployment --path=/usr/local/share/gems to install my bundled gems.
The problem is that the bundle install creates a folder ruby and puts the gems folder inside the ruby folder.
When this happens my ruby code is unable to find the gems in its default path.
Looks like I am missing some configuration parameter. Help please.
Maurício Linhares comments in the question has resolved the issue.
When using bundler to install gems use bundle exec ruby. When the bundle install --deployment happens the path information goes into .bundle/config
bundle exec ruby path-to-ruby-script.rb
The above execution Will find the gems installed by the bundle command.
Alternatively, if you want to force installation to the system gem location, I believe bundle install --deployment --system will do what you want.

Ruby - Could not find i18n-0.6.1 in any of the sources

I'm trying to install Redmine, but I'm in trouble on the final steps.
I never used a Ruby environment before, I'm a complete beginner.
$ RAILS_ENV=production rake db:migrate
Could not find i18n-0.6.1 in any of the sources
Run `bundle install` to install missing gems.
(bundle install in not helping.)
So I tried to 'gem install i18n -v 0.6.1', telling me '1 gem installed' and everything ok.
And it still doesn't work, and still don't get i18n (in any version) when I 'gem list'
The previous answer doesn't fix anything for me, I'm not using passenger.
Thanks.
EDIT : I found the dir where my gems are, /var/lib/gems/1.8/gems
in18-0.6.1 and other gems are here, but not listed in 'gem list'
EDIT 2 : Ok, my problem is more precise now. I'm actually trying to write a puppet script to install Redmine, and the 'bundle install' is actually working on a command line, but not in an exec puppet resource.
If you have problem with installing gems on remote and have not frequently updated project, you can cache gems and add them to git by bundle package and installing them after by
bundle install --local

How to make gem install command only install when not installed or update needed

i've read the documentation from rubygems site, but i guess the "gem install" command always reinstall, recompile everything, even if the same version already installed..
how to make gem install command only install when needed?
It looks like the --conservative flag will make the gem command do what you want.
gem install rake --conservative
From the documentation gem install --help:
--conservative Don't attempt to upgrade gems already meeting version requirement
You may want to use something external like gembundler to handle project’s gem installation.
If you must use rubygems directly for this, a command like
ruby -e "puts `gem install GEMTOINSTALL` if(`gem list --no-versions | grep GEMTOINSTALL`) == ''"
would do the job.
That is why we use bundle install. This command will look into the gemfile for the gems.
This Gemfile says a few things. First, it says that bundler should look for gems declared in the Gemfile at http://rubygems.org. You can declare multiple Rubygems sources, and bundler will look for gems in the order you declared the sources.
Bundler will connect to rubygems.org (and any other sources that you declared), and find a list of all of the required gems that meet the requirements you specified. Because all of the gems in your Gemfile have dependencies of their own (and some of those have their own dependencies), running bundle install on the Gemfile will install quite a few gems.
If any of the needed gems are already installed, Bundler will use them. After installing any needed gems to your system, bundler writes a snapshot of all of the gems and versions that it installed to Gemfile.lock.
When you run bundle install, bundler will (by default), install your gems to your system repository of gems. This means that they will show up in gem list. Additionally, if you are developing a number of applications, you will not need to download and install gems in common for each application. This is nice for development, but somewhat problematic for deployment.
In a deployment scenario, the Unix user you deploy with may not have access to install gems to a system location. Even if the user does (or you use sudo), the user that boots the application may not have access to them.
As a result, bundler comes with a --deployment flag that encapsulates the best practices for using bundler in a deployment environment.
The --deployment flag requires an up-to-date Gemfile.lock to ensure that the testing you have done (in development and staging) actually reflects the code you put into production. You can run bundle check before deploying your application to make sure that your Gemfile.lock is up-to-date. Note that it will always be up-to-date if you have run bundle install, successfully booted your application (or run your tests) since the last time you changed your Gemfile.

Can't install JSON gem

I need to install json because I get this error:
Could not find json-1.4.6 in any of the sources
I ran gem install json and bundle install but I was only able to install json-1.5.1 when I need json-1.4.6
I have gem 'json', '1.4.6' in my gemfile, so I'm not sure what's going on...
UPDATE
I get this error:
Installing json (1.4.6) /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/fileutils.rb:1216:in `chmod': Operation not permitted - /Library/Ruby/Gems/1.8/gems/json-1.4.6/CHANGES (Errno::EPERM)
After checking logs by running $ heroku logs
I found "An error occurred while installing json (1.4.6), and Bundler cannot continue.
Make sure that gem install json -v '1.4.6' succeeds before bundling."
I then removed 2 json entries from the Gemfile.lock and had no further issues.
Why did you run gem install json at all? Bundler takes care of that for you and will ensure that the correct version of each gem is installed (since sometimes dependencies require an older version). Run
gem uninstall json
bundle install
Also ensure you have source 'https://rubygems.org' at the top of your Gemfile.
As for the permissions info, you may have to run gem and bundle commands with sudo.
By the way, I highly recommend taking a look at and using RVM, particularly the gemsets feature. It will make your life infinitely better when developing Ruby apps. If you decide to do so, I'd also suggest trashing all the gems you've install using the system Ruby by running sudo rm -rf /Library/Ruby/Gems/1.8/. It's also important that when using RVM you don't have to use sudo when running gem (or bundle), which is not only safer but less typing too.
Please update your rubygems by executing the following command..
gem update --system
may be it will solve the problem. After updating your gem. Then run the following command to install json
gem install json
Now you can get json gem installed in your system.
Try:
$ sudo apt-get install ruby1.8-dev
If you're using rbenv, try rbenv rehash
I had this problem when trying to build a website with Jekyll.
Turned out I hadn't followed all the instructions at https://jekyllrb.com/docs/installation/ubuntu/
I don't know if it was the missing packages or commands into ~/.bashrc but it fixed the problem in two instances of Ubuntu in WSL
Remove the json entries from the Gemfile.lock file and try to re run bundle install..

Resources