There is the following code in Bundler:
group :production do
gem 'pg'
gem 'mysql2'
end
As you can see I use mysql2 on production only. Now I'm developing my app on my local machine, but I get the following error:
Could not find mysql2-0.3.15 in any of the sources
Run `bundle install` to install missing gems.
But I don't want to do it, I need production gems only on production VPS. How can I fix it? Thanks.
You just need to specify the option. See this too (it saves the option so you only have to specify it once)
bundle install --without production
Related
Whenever i run my rails server command on my command prompt it gives me the following error:
Since i am new to the Rails, I don't know much about it.
Guide me with the solution if possible..
I am using rails 5 on windows OS
Specified 'mysql2' for database adapter, but the gem is not loaded. Add gem 'mysql2' to your Gemfile
As your error says please add mysql2 in your Gemfile
# Gemfile
gem 'mysql2'
Also make sure you have mysql installed
The answer to your question is in the error message. You're using mysql2 as your database adaptor, but the gem isn't available.
add:
gem 'mysql2'
to your gemfile, then run bundle update from your project folder to install the missing gem.
You need to add
gem 'mysql'
in your Gemfile.
If its added then run command bundle install to install it. And check whether its installed successfully or not then restart server.
Also check your gem version with your Rails version.
In our team some people do not have pg gem installed on their machines. At the moment we use two seprate database configs that are being copied to database.yml. We had problems with that approach because we had to keep commenting out gem pg in our Gemfile. So I tried following in our Gemfile:
unless ['host1, 'host2'].include? `hostname`.strip!
gem 'pg'
end
It seemed to work, but the boss wants a better solution, so that he can test the app on his laptop without having to install Postgres and without having his hostname in the Gemfile.
Gem::Specification.all_names
doesn't show pg being installed although 'gem list pg --local' shows it is installed.
Trying to use gem list pg --local in the Gemfile doesn't work because the system seems to go into infinite loop if you don't have pg installed.
Is there something similar to 'Gem::Specification.all_names' that correctly shows list of installed gems that could be used in optional excluding of gems in a Gemfile. Or is there a better way to use gifferent Gems on different machines for the above mentioned scenario?
note
if File.open('./config/database.yml').read.each_line.first.index('Postgre').is_a?(Integer)
gem 'pg'
end
seems to work but now I get this when I run bundle install:
Your bundle is complete!
Gems in the group postgres were not installed.
Use `bundle show [gemname]` to see where a bundled gem is installed.
any idea where it comes form?
note 2
'Gems in the group postgres were not installed' was fixed after running: rm -r ./.bundle
One possible solutions would be to use a custom environment and bundler group.
You might have noticed this line in config/application.rb:
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
Which means running rails s -e bossmode would require the gems in:
group :bossmode do
# no pg in here...
end
An even better solution would be to convince your boss to KISS and use PG. The performance cost even on a lowly macbook air is tiny.
I'm having a problem running bundle update with mysql2. I don't really need mysql2 in development, and it works in production, so I want to just tell my gemfile the following:
gem 'sqlite3', :group => :development
gem 'mysql2', :group => :production
Unfortunately it still says bundle update fails because of mysql2:
An error occurred while installing mysql2 (0.3.14), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.3.14'` succeeds before bundling.
Any reason why this is, and what can I do instead?
It's not a good idea to leave out production gems while you are in development because you want to be prepared for production from the development phase of your project in that you don't want unseen errors when you deploy. That being noted, it's still possible to run bundle update without the production group.
Execute the following and you should see 'Gems in the group production were not installed':
bundle update --without production
For your case though, since you've already installed production group gems, you may want to clean your gems and install them as follows:
> bundle clean --force
> bundle install --without production
# For test purpose
> bundle update --without production
My organization has a number of in-house gems that are used in automated testing, but are not required for a production deployment. I am trying to use Bundler and so in my Gemfile I've wrapped those gems in:
group :test, :development do
gem 'dashboard_summary'
end
However, when I run:
$ bundle install --without staging development test
I still get
Could not find gem 'dashboard_summary (>= 0) ruby' in the gems available on this machine.
I'm trying to understand why Bundler isn't ignoring that gem when I've told it to.
This is expected behaviour. From the docs:
While the --without option will skip installing the gems in the specified groups, it will still download those gems and use them to resolve the dependencies of every gem in your Gemfile(5).
Whilst an up to date Gemfile.lock might suggest that the dependencies don’t need to be resolved again, it looks like all gems are downloaded even in this case.
You didn't define any group that includes staging, development and test. Your group only had test and development.
Bundler is trying to ignore a group which has all three name in it, so you can add staging to
group :test, :development, :staging do
gem 'dashboard_summary'
end
or you can use
$ bundle install --without test development
I'm not sure why you have staging in there? but this should work
bundle install --without test development
You could also set the config environment variable documented in BUNDLE_WITHOUT in bundle config.
You could use
gem 'dashboard_summary', require: false
This would not load the gem on startup and you would have to require it when you wanted to use the gem. This may help if you need to keep dashboard_summary in your Gemfile because of dependencies, but save the time it takes to load and not get the error you are getting now. It's at least something to try.
to load my rails 3.2.8 app on Heroku, I put in Gemfile:
group :development, :test do
gem 'sqlite3'
end
group :production do
gem 'pg'
end
and I gave 'bundle install', forgetting to give '-- without production' and now when I give 'rails s', the console gives me error: Could not find railties '..my gems..' (gem: load error) and Heroku gives me error when I give: heroku run rake db:migrate..In Gemfile I just put the gem 'sqlite3' and gave 'bundle install' but same error. How can I go back with bundle?
From your comment, it looks like you do not have bundler installed or at least accessible in this environment.
Are you using rvm ? If so are you in the right gemset with the right ruby version ?
You will have to fix your local environment before make it working on Heroku in order to have a proper Gemfile.lock, also when it will work on local, it should work fine on heroku.
If you do not use rvm / rbenv, maybe you can start by installing bundler properly : gem install bundler