I use Capistrano to deploy a Rails 3.2.1 app that uses mysql2 adapter.
The app is working fine locally on windows, but when i try to deploy to a linux server, Capistrano throws the following error:
Please install the mysql2 adapter: gem install activerecord-mysql2-adapter (mysql2 is not part of the bundle. Add it to Gemfile.)
Please note that i'm tracking Gemfile.lock on GIT but i noticed this:
...
mysql2 (0.3.11-x86-mingw32)
...
The lock file locked the version which is fine, but i think it locked the windows version (x86-mingw32) which might not work on linux.
Any one had the same issue? I don't want to untrack Gemfile.lock because it's not recommended.
My deploy.rb is like:
require "bundler/capistrano"
load "deploy/assets"
... configuration here ...
P.S. I also noticed other gems locked with this part "x86-mingw32", like bcrypt-ruby
Don't worry about any gems with "mingw32" in your Gemfile.lock. Take a look at your Gemfile. Do you have the following line?
gem 'mysql2'
Given this, did you run bundle install at the linux server (or did you put this functionality to your capistrano recipe?)
BTW, if you have any windows-specific gems, and you want to be sure that they are only loaded in this context, use the following condition:
platforms :mswin, :mingw do
# placeholder for gems in a windows environment
end
Related
C:\sites\srhapp>rails generate controller home index
C:/Ruby21/lib/ruby/gems/2.1.0/gems/execjs-2.5.2/lib/execjs/runtimes.rb:48:in `au
todetect': Could not find a JavaScript runtime. See https://github.com/rails/exe
cjs for a list of available runtimes. (ExecJS::RuntimeUnavailable)
This are the error messages i get. kindly help me out .
Install nodejs. That may help here.
Follow this.
Now that you have Nodejs installed, see if any of these can help with the error you are getting (I was going to comment on jon snow's answer, but my suggestions became too long.):
Make sure you have C:\Windows\System32 in your system's PATH variable.
Close and then restart your command console.
Type node -v into the console. Does Nodejs respond?
Change the therubyracer line in your Gemfile to gem 'therubyracer', {:platforms => [:ruby]}. As far as I know, therubyracer isn't for Windows, but declaring it this way lets it still be used in Heroku if you plan on using that later. Run bundle install after you make this change.
Edit
Do you necessarily need Puma in your Windows development environment? If you only need it for deployment on Heroku, the easiest way that I have found to get around its difficulty with Windows is by putting it into the production group along with any other gems Heroku requires.
Gemfile
...
group( :production ) do
# Serves static assets in Heroku deployment.
gem 'rails_12factor'
# Web server for use with Heroku.
gem 'puma'
# Database used by Heroku.
gem 'pg'
end
...
That way, you can simply exclude those gems when you bundle install in your local development environment.
$ bundle install --without production
If you really do need Puma on a Windows environment, you will have to install OpenSSL libraries and headers (so I have heard; I haven't tried it myself). The comment by luislavena on this page should help you in that case.
I'm running a Rails 3.2 app that depends on an offline gem, chilkat. (http://www.chilkatsoft.com/ruby.asp).
I've gotten this to work on my development environment by doing the following:
Unpacking the gem into my vendor/gems folder
Adding this line to my Gemfile
gem 'chilkat', '9.4.1', path: 'vendor/gems/chilkat-9.4.1-universal-darwin-12', require: false
(These steps were taken from How to use Bundler with offline .gem file?)
BUT when I push the code to Heroku, the app crashes with the error:
/app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.14/lib/active_support/dependencies.rb:317:in `rescue in depend_on': No such file to load -- chilkat (LoadError)
Do you know what I need to do to get the gem installed properly on Heroku? Thanks!
Ok I figured out the issue. The Chilkat gem I'm using has OS-specific versions, and the version I unbundled in vendor/gems is for OSx won't work on Heroku/AWS. So even if the path would have worked correctly in Heroku, the gem itself would not.
The problem I face now is because the Chilkat gem is OS-specific, Bundler will generate a Gemfile.lock file specific to the OS on which bundle install was called (OSx in my case). That OSx-specific Gemfile.lock is incompatible with AWS's machines, so Heroku complains that I can't push the code since the Gemfile.lock is inconsistent with what is expected.
This appears to be a known issue with Bundler (How to add Mac-specific gems to bundle on Mac but not on Linux?). I could just avoid committing Gemfile.lock, but we rely on the version dependency management that Gemfile.lock provides. And I don't want to get all the developers on my team to switch to developing on Linux/Unix. Anyway that's a separate issue so I'm closing this for now. Thanks to the people who commented!
We use capistrano for rails deployment. Here is a strange error when running bundle install on production server.
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`.
You have added to the Gemfile:
* rails (= 3.1.3)
* mysql2 (>= 0.2.6)
You have deleted from the Gemfile:
* rails (~> 3.1.3)
Gemfile on production server was manually changed and then, this error comes out. This is a new production server and we plan to run rails 3.1.3. We rebooted the linux server and it did not help. Is there way to fix the problem? thanks so much.
I guess, you're using some deployment solution, like Capistrano. If this is the case, change the Gemfile on a development machine, run bundle install, commit everything into the repository and deploy again.
Don't ever change code manually on the server, it's gonna be bad for your karma.
Edit:
If you want to use some specific gems in production only, add them to production group.
# Gemfile
group :production do
gem 'mysql2'
end
i was told that using config.gem alongside :path => "path/to/dir" would work.
on server restart though environment.rb does not pull the gem im pointing at.
anyone have any ideas?
SO it seems running bundler was the way to go.
in console:
gem install bundle
then
gem list
copy those gems and format them like this: http://gembundler.com/gemfile.html. Then place them in Gemfile (home dir)
NOW for the LOCAL gem ( which i have stored in project/local_gems/thin-1.2.10 ) i placed this in the Gemfile
gem "thin", :path => "local_gems/thin-1.2.10/"
next:
bundle install
NOW... heres the tricky bit.. when running 'thin' as you web server its necessary to run thin commands within the bundled environment SO:
bundle exec thin start
and there you have it ! Running a ' thin ' web server on rails 2.3.8 using bundler!
Its is worthwhile to note that you WILL NOT see updates to you local gem file until:
- you stopped the server ( ctrl + c )
- saved all files associated with that gem,
- redo 'bundle install'
- THEN run server again to see changes
Are you sure you are using rvm, and the rvm version you want to be using, when you are installing your gem? You might be trying to install the gem using your system ruby. If all that is the case, then you might want to set your default rvm version to be the one you want to use. Then you will always get the gems into that rvm version.
My rails applications run on a shared host. I don't have access to a commandline and can't run the bundle command. I can run a few pre-selected rake commands.
On my development machine, I've done bundle install --deployment, so that all my gems are in vendor/bundle.
Problem is, however, that my development machine is not compatible with my shared host (32/64 bits), so the native extension of the mysql2 gem doesn't work on the shared host. The shared host does have the mysql2 gem installed, though.
If I remove 'mysql2' from the Gemfile, I get this error: !!! Missing the mysql2 gem. Add it to your Gemfile: gem 'mysql2' (<= this was because I had the adapter set to mysql instead of mysql2 in database.yml:
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: db
pool: 5
username: user
password: pass
socket: /var/run/mysqld/mysqld.sock
(same for test/production)
If I keep gem 'mysql2' in my Gemfile, I get this error (which makes sense, because of the native extension was compiled on a different machine:
/home/project/vendor/bundle/ruby/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.so: wrong ELF class: ELFCLASS32 - /home/project/vendor/bundle/ruby/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.so
If I remove gem 'mysql2', I get:
Please install the mysql2 adapter: 'gem install activerecord-mysql2-adapter' (no such file to load -- active_record/connection_adapters/mysql2_adapter)
I would like to specify which gems should be loaded from my own applications vendor/bundle directory and which gems from the system gem directory.
Is this possible with bundler?
What's the best solution for this problem?
Thanks.
Check your database.yml file. Make sure you are not referring to the adapter that you don't have installed in your environment.
Have you checked your gemlock file for -x86 gem references? I had a similar issue deploying from windows xp to 64-bit ubuntu. Modify these to remove the -x86 part and run bundle install again, this should build the 64-bit native gem if all the libraries are on the instance.