How to manually update a gem in the capstrino environment - ruby-on-rails

We have a codebase, which is used as a gem in the older codebase. After deployment we see that, the older code in the gem is getting executed. Now we want to manually update the gem in the server
here is what capistrino is doing
bundler:install
01 ~/.rvm/bin/rvm 2.3.0 do bundle install --path /home/deployer/bla/shared/bundle --without development test --deployment --quiet
01 Warning, new version of rvm available '1.28.0', you are using older version '1.27.0'.
01 You can disable this warning with: echo rvm_autoupdate_flag=0 >> ~/.rvmrc
01 You can enable auto-update with: echo rvm_autoupdate_flag=2 >> ~/.rvmrc
So I went into the bundle folder and I did
bundle update gem_name.
It said it could not find the gemfile. And the contents of the bundle folder is just ruby. Is there a way that I can manually update the gem? Any help would be greatly appreciated.

Bundler doesn't work that way. Even if you updated the gem, if your Gemfile/Gemfile.lock still reference the old version, that's the one that will be loaded. If it's not available, then your app won't boot.
If you want to update the gem in your production environment, you need to run bundle update gem_name inside your app directory, where the Gemfile is located. Assuming you haven't picked a too-specific version in your Gemfile, this will modify your Gemfile.lock and install the new gem.

Related

Capistrano bundle install trying to install development gems on server

I have a development gem that is trying to be installed on the server via capistrano and is failing b/c i'm pointing to github at the moment.
Why is this gem trying to be installed on my server anyways?
Gemfile snippet:
gem 'capistrano-local-precompile', '~> 1.0', :git => 'git#github.com:stve/capistrano-local-precompile.git', :branch => 'cap3', :group => :development, require: false
Capistrano snippet output:
00:08 bundler:install
01 ~/.rvm/bin/rvm 2.3.3 do bundle install --path /var/www/csmschedule/shared/bundle --without development test --quiet --no-cache
01 The authenticity of host 'github.com (192.30.253.112)' can't be established.
01
01 RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Is the GIT section for capistrano-local-precompile present in your Gemfile.lock, and is that lock file committed to your repo? In other words, have you run bundle install locally, committed both Gemfile and Gemfile.lock, and pushed those changes before running cap deploy?
Bundler needs to know the dependencies of the capistrano-local-precompile gem in order to do version resolution. Even if you specify --without development, it still needs this information (because version requirements of development gems can affect version resolution for production ones).
If your lock file is not present or if it is out of date (i.e. capistrano-local-precompile is not in the lock file), then Bundler needs to download the gem from GitHub in order to update the lock file.
On a related note: I notice you are not using --deployment in the bundle command on the server. That is probably not a good idea. You should use --deployment so that Bundler checks that your Gemfile.lock is up to date, as described here:
http://bundler.io/v1.15/man/bundle-install.1.html#DEPLOYMENT-MODE

Ruby version error on deployment with capistrano

I am getting ' Your Ruby version is 2.3.3, but your Gemfile specified 2.0.0' when I am trying to deploy with Capistrano.
my gemfile specifying 2.3.3
ruby "2.3.3"
00:27 bundler:install
01 /usr/local/rvm/bin/rvm 2.3.3 do bundle install --path /var/www/mypath/shared/bundle --without development test --deployment --quiet
01 Warning, new version of rvm available '1.29.1', you are using older version '1.29.0'.
01 You can disable this warning with: echo rvm_autoupdate_flag=0 >> ~/.rvmrc
01 You can enable auto-update with: echo rvm_autoupdate_flag=2 >> ~/.rvmrc
01 Your Ruby version is 2.3.3, but your Gemfile specified 2.0.0
Don't know what the problem is from looking at this, but here is how I would debug it.
Check your Gemfile and Gemfile.lock and verify it is showing 2.3.3. Also Capistrano pulls directly from the repository rather than uploading your local files so verify your Gemfile and Gemfile.lock on the remote machine have the right versions. If they don't, verify you have committed the latest Gemfile and Gemfile.lock and pushed them up to your repository. You can also try just running bundle on the remote machine to take Capistrano out of the equation.

Why is "install" run twice?

I'm going through Micharl Hartl's well known Rails tutorial, and this piece is confusing me. Every time a new app is set up, these commands are run:
$ bundle install --without production
$ bundle update
$ bundle install
I don't really get why install is being run twice. What is the effect of these three commands run in this sequence?
You should not have to run bundle install twice as bundle update will also install all of your gems (as well as updating them to their most current version). I have not read the tutorial you mentioned but perhaps the purpose of the second install is to install all of the gems, including those reserved for production.
Your second question, what is the effect of these three commands:
bundle install --without production
Inspect the gemfile, ignoring gems that are reserved for production
Resolve all dependencies
Install all gems and dependent gems
Save the exact version of each gem to Gemfile.lock
bundle update
Inspect the gemfile
Resolve all dependencies from scratch using the newest version of each gem and completely ignoring Gemfile.lock
Install all gems and dependent gems
Save the exact version of each gem to Gemfile.lock
bundle install
Because this is the first run of the production gems, inspect the gemfile and resolve dependencies of the production gems
Use Gemfile.lock for exact versions of all other gems to be installed
Install all gems and dependent gems
Save the exact version of each gem to Gemfile.lock
Hoped this helped, for more detailed info about the two commands check out this and this.
$ bundle install --without production prevents bundler from installing any of the production gems. It also gets saved in your local repository and you don't have to run it more than once. Any subsequent run of bundle install will include --without production.
bundle install installs only the missing gems from your Gemfile, while bundle update updates/installs every single gem to the latest version as specified in the GemFile..

Gem list contains multiple dependencies to a certain gem

I had unicorn 4.5.0 and after I did bundle update, I observe different versions of the same gem even though I wanted to use the latest version.
unicorn (4.6.1, 4.5.0)
How do I instruct the bundler to just keep the latest version.
As far as I can see you cannot instruct bundler to keep only the latest version when updating. You can delete all the old versions of all gems in one go:
bundle exec gem cleanup
(Reference)
You can instruct bundler to just use one version by putting that version in the gem file. Sometimes, I have had conflicts with rake, even though I did not explicitly have rake in my Gemfile, so I had to put the rake version that would be usable by all the other gems at the top of my Gemfile.
If your issue is that you used to use unicorn 4.5.0, and now it has installed unicorn 4.6.1 in you local gem source, you can tell gem to uninstall the version you no longer need.
gem uninstall unicorn --version 4.5.0
If you did a bundle --deployment and populated the vendor/bundle directory, and that is where you want to remove the gem from, then I usually just delete the gem directory, however, I think you can run bundle with --path, like the following:
bundle --deployment --path vendor/bundle
gem uninstall unicorn --version 4.5.0
When you run bundler, it remembers the settings. I painfully discovered this regarding the --without switch. The --path setting will tell gem to use the local vendor/bundle directory as your local gem source. Remember to set the path back by running bundle again.

How do I use bundler to get a gem from a git repository?

Authlogic has a couple unfortunate deprecation warnings that are fixed in a fork.
How do I use this forked version? I tried adding the following to my Gemfile:
gem 'authlogic', :git => 'git://github.com/railsware/authlogic.git'
And it didn't work quite that well. I started getting:
git://github.com/railsware/authlogic.git (at master) is not checked out. Please run bundle install
And
The git source git://github.com/railsware/authlogic.git is not yet checked out. Please run bundle install before trying to start your application
Assistance will be rewarded with virtual cookies.
Have you tried running bundle install after removing Gemfile.lock?
rm Gemfile.lock
bundle install
Your Gemfile configuration should work, I was able to use the same for and my bundle install command executes as does my bundle list command.
My other suggestion would be removing you ~/.bundler and .bundle directories and checking that you have properly configured git.
You need to run bundle install from the terminal after updating your Gemfile.

Resources