Changing Ruby version during deploy - ruby

I have a box with 3 Rails apps on it. I wan't to upgrade one of the apps so that it uses Ruby 2.0.0, while leaving the others running on 1.9.3-p394. I have both those Rubies installed via Rvm.
I'm trying to control the Ruby version that each app uses via it's Gemfile.
# Gemfile
ruby '2.0.0'
So, I changed the version number in the Gemfile locally, made sure it all worked, committed and now I'm trying to deploy the change to the server.
However, the cap deploy fails at this point
bundle install --gemfile [path to release Gemfile] --path [path to app bundle] --deployment --quiet --without development test
because
Your Ruby version is 1.9.3, but your Gemfile specified 2.0.0
This is correct technically, my Gemfile does specify 2.0.0 and the app is currently running on 1.9.3. I'm trying to make it change versions before bundling though. How do I do that?

Your PATH is not set up correctly. You probably don't have bin: as the first entry in your path. That would lead to this error.
Even if you're not using Heroku it's worth reading this page on troubleshooting that issue: https://devcenter.heroku.com/articles/ruby-versions
Here is a link to an answer which will explain how to change your PATH on the server: Capistrano: Can I set an environment variable for the whole cap session?

If you have rvm maybe you can try to do
rvm use 2.0.0
before your bundler call.

If you're using rvm set the default to ruby 2.0.0 on your server
rvm --default use 2.0.0
Resolved the problem for me deploying to an AWS server from my mac - but I guess if I need to update my older sites I'll have to set the default back to 1.9.3 before deploying.

Related

Ruby on rails 4.1.6 + Capistrano 3: purge gems on deployment server

Hy guys,
I have a server with apache, passenger 4.0.50, ruby 2.1.2 (started with 1.9.3), RVM and dozen of ruby on rails 4.1.x apps.
RVM is used only to manage ruby versions.
Follows the bundler configuration for each app:
BUNDLE_FROZEN: '1'
BUNDLE_PATH: "/PATH/TO/DEPLOYED/APP/shared/bundle"
BUNDLE_WITHOUT: development:test
BUNDLE_DISABLE_SHARED_GEMS: '1'
In order to save disk space (a lot of space) I would like to remove old gems of each application using bundle clean
The idea is to keep 2 releases (capistrano) and to run the command before a new deploy in order to keep gems for the last release.
The problem is that gems installed whit ruby 1.9.3 are not removed.
Can you please confirm that:
Gems for ruby 2.1.2 are installed in /PATH/TO/DEPLOYED/APP/shared/bundle/ruby/2.1.0/gems
Gems for ruby 1.9.3 are installed in /PATH/TO/DEPLOYED/APP/shared/bundle/ruby/1.9.1/gems
I can remove directory /PATH/TO/DEPLOYED/APP/shared/bundle/ruby/1.9.1/gems since I'm not using ruby 1.9 anymore
Many thanks in advance for your help.
Mauro
You dont use ruby 1.9.x anymore, so just remove the gems directory for it.

Apache/Ruby/Passenger misconfigured after Ubuntu 12.04 to 14.04 update

Well, I have to admit, that I'm down today. I've updated my Ubuntu and that rendered Redmine 2.1.2 completely dead. Any suggestions as of to what should I update or reconfigure? I'm trying not to use Ruby/Rails/Passenger blindly but it's tough as it's not my expertise. I'd like to USE Redmine instead.
Top of the Passenger error log is below, but feel free to check whole page at http://redmine.teacloud.net:
It looks like Bundler could not find a gem. Maybe you didn't install all the gems that this application needs. To install your gems, please run:
bundle install
If that didn't work, then the problem is probably caused by your application being run under a different environment than it's supposed to. Please check the following:
Is this app supposed to be run as the nobody user?
Is this app being run on the correct Ruby interpreter? Below you will see which Ruby interpreter Phusion Passenger attempted to use.
-------- The exception is as follows: -------
Could not find rake-10.3.2 in any of the sources (Bundler::GemNotFound)
/var/lib/gems/1.8/gems/bundler-1.3.4/lib/bundler/spec_set.rb:92:in `block in materialize'
• I have no idea, what user should this app supposed to be run as. Everything else uses www-data by default, however the redmine application folder in filesystem is owner by root.
• Everything was working for two years on ruby 1.8 that is not on my system now. I've managed to install lowest version 1.8.7, latest 2.1.2... and I have no idea where does the 1.9.1 get from.
• I don't understand how 'bundle install' and 'bundle update' is related to current ruby version switched to using rvm.
• I am not sure, at what point will my Redmine MySQL database be migrated or destroyed if I'll need to upgrade Redmine (so I have backup).
• bundle install didn't help, Apache runs ruby 1.9.1
Solution was simply as follows (whole failure path is documented here http://www.redmine.orgenter code here/boards/2/topics/43500?r=43514):
• Everything happens in the Redmine's installation folder:
• Went to GitHub (https://github.com/redmine/redmine/blob/master/Gemfile) and copied fresh database section to Redmine's Gemfile (ignoring the fact that I have Redmine 2.1.2 and Gemfile is far newer)
$ rvm use system
$ bundle install

deploying a specific git version of a gem into passenger via rvm global gemset

We've a deploy issue I'm having with passenger using a specific github
version of the handsoap gem, which is specified in the Gemfile.
bundle states:
Using handsoap (1.1.8) from git://github.com/unwire/handsoap.git (at e6f79ec)
[ rubyapp]$ bundle show handsoap
/usr/local/rvm/gems/ruby-1.9.3-p286#global/bundler/gems/handsoap-e6f79ec9d6a3
[ rubyapp]$ bundle show capybara
/usr/local/rvm/gems/ruby-1.9.3-p286#global/gems/capybara-1.1.3
(There's many other gems but I thought I'd add capybara to show where they are. There's no other specific github versioned gems)
Sadly we've not got root access to change to another gemset - i.e. not
global and it was installed before the project was setup, so we were not able to specify a custom gemset before, as you would in the local development environment. This version of the gem is needed unfortunately.
Passenger reports:
git://github.com/unwire/handsoap.git (at e6f79ec) is not checked out.
Please run bundle install (Bundler::GitError)
I've tried a gemset empty global , and a following bundle install
I've tried a gemset empty global , and a following bundle install
I've tried
rm /usr/local/rvm/gems/ruby-1.9.3-p286#global/bundler/gems/handsoap-e6f79ec9d6a3
and a bundle install
all which give the same passenger error as specified above.
Any help would be appreciated. The application has been working previously within the global gemset - but with a previous version of handsoap, but now it's time for a new deploy of the code.
Spent a couple of hours now trying out different options.
Cheers in advance,
Ian.

does every gem have its own rake?

Does every gem have its own rake? Because I was doing android development and I created app using the z$ rhogen app z. and then i did $rake run:android and the android emulator came up. But when I create an app using $rhosync app <appname> then migrate to the root of the app folder and do $rake:dtach install then the rake uses my older version of Ruby 1.8 where as my new and active Ruby version is Ruby 1.9.2. I dont know where to change the config file of the app or gem I am not sure to make Ruby 1.9.2 as my default ruby when I do $rake dtach:install.
As Alex said, rake tasks are not needed in order to have a gem.
What environment are you working on? RVM is a nice way to manage you ruby environments and manage multiple versions of ruby on unix based systems (OS X/ubuntu/debian). Have a look here http://beginrescueend.com/
No, not all gems have rake tasks.

Unable to update gems on production server

Can not update gems on production server.
I've tried bundle install --deployment and bundle install --without development test
But keep getting:
You are trying to install in deployment mode after changing
your Gemfile. Run `bundle install` elsewhere and add the
updated Gemfile.lock to version control.
If this is a development machine, remove the Gemfile freeze
by running `bundle install --no-deployment
EDIT
I don't know if this is correct, but needed a quick fix. I ran bundle install --no-deployment then bundle update then ran bundle install --deployment again
The instructions are probably a bit confusing. It's saying that you've modified your Gemfile on your development machine and just pushed those changes rather than running bundle install BEFORE committing the changes.
By running bundle install you will update your Gemfile.lock file. This should be pushed to your server as it's more important than Gemfile. Consider the Gemfile the plans for the Gemfile.lock file.
Always remember to:
Run bundle install if you change your Gemfile, even just to make sure. If it's too slow, pass --local through which forces it to only use local gems to resolve its dependencies.
Commit both the Gemfile and Gemfile.lock file to your repository
Deploy both the Gemfile and Gemfile.lock to your production servers to ensure that they're running the exact same dependencies as your development environment.
Running bundle update by itself can be construed as dangerous that will update all the dependencies of your application. It's mainly dangerous if you don't have solid version numbers specified in the Gemfile. I wrote about it here.
FWIW I had this problem and fixed it by removing some conditional statements from my Gemfile (conditionals on OS) and rerunning bundle.
FYI: You can also get this error if you use source blocks like this:
source 'https://rails-assets.org' do
gem 'rails-assets-jquery'
end
You'll see an exclamation point in the Gemfile.lock for this gem:
rails-assets-jquery!
Just define the additional source normally, i.e.
source 'https://rails-assets.org'
gem 'rails-assets-jquery'
(BTW cf. here about using multiple gem sources.)
This can be caused by an old version of the bundler gem on the server you're deploying to (in this case production). Logging into the server and running a gem update bundler resolved the issue for me. The server I was deploying to was running version 1.7.4 and the current version was 1.9.
I had an issue with my production server still using an old version of a gem, even though the Gemfile.lock showed the correct, updated version. My production server was running on Unicorn - and shutting down / starting it back up again fixed the issue - instead of sending the HUP signal, which did jack all to fix the issue.
bundle install failed on my "development" machine because of the mysql-gem on osx...
I also needed a quick fix. So I cloned the repo to a new folder on the production machine, ran "bundle install" there and committed the Gemfile.lock to the repo.
I have had this problem (Ubuntu 12.10 & 12.04, one of which behind a proxy server).
My problem was that I had some git:// protocols in the Gemfile. Changing this to http:// helped me get it all working.

Resources