Failed to install "Mysql2" version 0.5.2 - ruby-on-rails

I tried all methods of here.
But still, the same error occurs.
An error occurred while installing mysql2 (0.5.2), and Bundler cannot
continue.
Make sure that gem install mysql2 -v '0.5.2' --source 'https://rubygems.org/'
succeeds before bundling.
My spec is:
MacOS Mojave 10.14.1
Ruby 2.5.3p105
Mysql 8.0.12 with Homebrew
Gemfile:
gem "rails"
gem "mysql2", "0.5.2"
Could you kindly tell me a solution?

This is a very good post. I was facing the same issue using mac. What I ended up doing was the following.
I changed the permission for the Gemfile. I used chmod 755 Gemfile.
I used sudo bundle install. This allowed me to install all the gems in the Gemfile.
I did a rake db:create and rails server.
Got things working. Hope it fixes your issue too.

I had the same issue, when setting up a new machine.
Just running
brew install mysql
fixed the failing mysql gem installation for me.

Don't know if this will help, but I had imilar problems on Mac with MySQL twice. First time I just did a complete reinstall, I made sure there were no MySQL files left in the system. I think I followed this guide. The second time I read that it's an issue with symoblic links which I managed to fix with brew prune (I see that it might have been renamed to brew cleanup now - worth to check both).

Related

trouble installing postgresql for rails app

So I would like to deploy my rails app on heroku right? Wanna switch from sql3 to postgresql. Should be simple but I keep getting an error when trying to bundle with gem 'pg' in my gemfile. I used homebrew to install postgresql with all its native extensions before trying to bundle. Any ideas? I am on Mac OSX high sierra.
An error occurred while installing pg (1.1.3), and Bundler cannot
continue.
Make sure that gem install pg -v '1.1.3' --source 'https://rubygems.org/'
succeeds before bundling.
That's all I get for the error. Not helpful. I went ahead and uninstalled postrgresql that I installed locally to my machine from their website as well as with homebew. Gonna start from scratch. I haven't done this in years so any help would be appreciated!
I've run into this before where you attempt to install the PG gem, but postgres is not yet installed. Even if you install postgres after that, you'll still run into troubles (this has to do with required libraries not being available or not found). I would recommend uninstalling both, then installing Postgres first, then the PG gem. This is a common gotcha, unfortunately: Installing PG gem on OS X - failure to build native extension Also, I would recommend https://postgresapp.com/ if you continue to have trouble installing PG or having the gem not see your install properly.
After tons of research and trying everything, found an older question on stackoverflow from 2014. If you install postgresql with homebrew like I did, running the command ARCHFLAGS="-arch x86_64" gem install pg will install the gem if bundling or gem install pg don't work. Hope that helps other people who might be stuck like I was

Could not find a valid gem 'mysql2-0.3.18.gem'

i am new to Ruby on rails and i have facing this problem during Rails installation. I have searched a lot and tried many solution which were available on stackoverflow but nothing work for me. Please help how can i get out of this problem..
I have had this problem before, and the reason you are getting this method, is because you are trying to download from an https website.
My guess is you are trying to install all the gems in your gemfile and bundle install didn't work. It would give you a message like
bundler cannot continue. Please make sure gem install samplegem succeeds
Change the following line in your gemfile
source 'https://rubygems.org'
to
source 'http://rubygems.org'
and run bundle
alternatively, you could do the following
gem install mysql2 -s http://rubygems.org
Either way, you should be able to install the gem.
Had you already installed mysql in your machine? The same experiencing happened with me. I was using a virtual environment and trying to install gem mysql2 but I forget that I haven't mysql in my "main" environment.
I ran the following and mysql2 installed successfully.
gem install mysql2 -s http://rubygems.org
But the problem remaied the same when re ran the "bundle install"

Why won't bundler install JSON gem?

I get the following error when attempting to run cap production deploy.
DEBUG [dc362284] Bundler::GemNotFound: Could not find json-1.8.1.gem for installation
DEBUG [dc362284] An error occurred while installing json (1.8.1), and Bundler cannot continue.
DEBUG [dc362284] Make sure that `gem install json -v '1.8.1'` succeeds before bundling.
It may be important to note that this deployment was working, than I upgraded to Ruby 2.1.0 to remove an encoding error. I upgraded locally which worked fine. I ran rvm install 2.1.0 and rvm use 2.1.0 then changed my .ruby-version file to reflect this Ruby upgrade.
The bundle install command works locally, but produces the same above error when I ssh onto the destination server and run this command.
If I run gem list I can see this in the list of gems.
...
jquery-rails (3.0.4)
json (1.8.1)
less (2.3.2)
...
If I try the recommended solution gem install json -v '1.8.1' Locally and on the destination server I get the following output:
Building native extensions. This could take a while...
Successfully installed json-1.8.1
Parsing documentation for json-1.8.1
Done installing documentation for json after 0 seconds
1 gem installed
So it appears the gem is installed, right? Why is this happening? How can I solve this? Any help would be greatly appreciated.
$ bundle update json
$ bundle install
So after a half day on this and almost immediately after posting my question I found the answer. Bundler 1.5.0 has a bug where it doesn't recognize default gems as referenced here
The solution was to update to bundler 1.5.1 using gem install bundler -v '= 1.5.1'
Run this command then everything will be ok
sudo apt-get install libgmp-dev
if you are in MacOS Sierra and your ruby version is 2.4.0.The ruby version is not compatible with json 1.8.3.
You can try add this line in your Gemfile:
gem 'json', github: 'flori/json', branch: 'v1.8'
This works for me!
To solve this problem, simply run:
bundle update
It will update the version of your bundler. Then run:
bundle install
Your problem will get solve. Solution is well explained here.
I found the solution here. There is a problem with json version 1.8.1 and ruby 2.2.3, so install json 1.8.3 version.
gem install json -v1.8.3
You should try
$ sudo gem install json -v '1.8.2'
in my case (Ubuntu 14.04) that didn't work directly and I had to do this:
$ sudo apt-get install ruby-dev
and then I could install the gem and continue. Had one more problem that was fixed by:
$ sudo apt-get install libsqlite3-dev
Hoping helps.
If the recommended answer didn't help because you are already using a newer version of bundler. Try the solution that worked for me.
Delete everything inside your vendor folder.
Add a line to your gemfile
gem 'json', '1.8.0'
Then run - bundle update json.
It seems to be an issue with 1.8.1 so going back to 1.8.0 did the trick for me.
I ran into this error while trying to get a project to run on my local dev box (OSX 10.6), using Sinatra and Postgresql (through activerecord), running on an rvm'd ruby 2.1. I found my answer here: https://github.com/wayneeseguin/rvm/issues/2511
My exact problem (after the first block of log entries):
I also get an error when trying to build native extensions for gems
The answer:
rvm reinstall 2.1.0 --disable-binary
The explanation:
OSX does not have a package manager so all libraries have to be installed manually by user, this makes it virtually impossible to link the binary dynamically, and as you can see there are problems with the (pseudo)statically linked binary.
For the sake of completeness, I had first forgotten to update rvm (rvm get head), which yielded some other errors, but still needed the --disable-binary flag once I had done so.
bundle update json. Helped to get through.
When I tried to install the json gem using gem install json separate from just using bundle install I got ERROR: Failed to build gem native extension., looking that up I found using
apt-get install ruby-dev
did the trick
For OS X make sure you have coreutils
$ brew install coreutils
$ bundle
This appears to be a bug in Bundler not recognizing the default gems installed along with ruby 2.x. I still experienced the problem even with the latest version of bundler (1.5.3).
One solution is to simply delete json-1.8.1.gemspec from the default gemspec directory.
rm ~/.rubies/ruby-2.1.0/lib/ruby/gems/2.1.0/specifications/default/json-1.8.1.gemspec
After doing this, bundler should have no problem locating the gem. Note that I am using chruby. If you're using some other ruby manager, you'll have to update your path accordingly.
I was missing C headers solution was to download it for Xcode, this is the best way.
xcode-select --install
Hope it helps.
Bundle was failing to install json -v '1.8.1' and deleting my Gemfile.lock and running bundle again solved this issue for me.
I installed the latest version of json:
gem install json
Then deleted the line json(1.8.1) from the Gemfile.lock and did a
bundle install
And then the Gemfile.lock file uses json(1.8.3) without erros
Switch ruby version from 1.9 to 2.2 with rvm did the job for me
For me, some of the answers mentioned earlier were helpful from understanding point of view, but those didn't solve my problem.
So this is what I did to solve issue.
Modified gemfile.lock to update json (2.0.2) (Earlier, it was 1.8.3)
Check the Bundler version installed (Bundler -v command). I had version 1.12.5 installed
Install bundler version 1.11.2 (using gem install bundler -v '1.11.2')
Then run bundle install
For macOS Sierra:
I ran into this error When i used bundler(v1.15.3) in Rails(v4.2) project.
The solution for me is gem uninstall bundler -v '1.15.3' and gem install bundler -v '1.14.6'.

Rails: Installing PG gem on OS X - failure to build native extension

It seems many others have had problems installing the pg gem. None of the solutions posed for others have worked for me.
I have tried to install the pg gem and postgres.app. The pg gem won't install. The first error I get is:
An error occurred while installing pg (0.17.0), and Bundler cannot continue.
Make sure that gem install pg -v '0.17.0' succeeds before bundling.
The installation advice about pointing my gem install to the config for pg fails with the following error message (which many others on this forum have encountered):
Failed to build native extensions... Results logged to /Users/melanie/.rvm/gems/ruby-1.9.3-p448/gems/pg-0.17.0/ext/gem_make.out
I don't know how to find or access this log file to search for further clues.
I also get an error message (command not found) when I try using the sudo apt-get install command. I've scoured this forum for the last 6 hours, trying each piece of advice to get pg working with my rails project.
I can't find advice about how to change a path, or specifically, what change is required. My which pg_config returns a file source. I've used that with a command to install pg using that config. It fails.
There are so many people that have had trouble with this. Many answers suggest homebrew. I've had to remove that because it threw up other issues.
Same error for me and I didn't experience it until I downloaded OS X 10.9 (Mavericks). Sigh, another OS upgrade headache.
Here's how I fixed it (with homebrew):
Install another build of Xcode Tools (typing brew update in the terminal will prompt you to update the Xcode build tools)
brew update
brew install postgresql
After that gem install pg worked for me.
If you are using Ubuntu try to install following lib file
sudo apt-get install libpq-dev
and then
gem install pg
worked for me.
I am using OS X Mavericks (version 10.9)
and when I run the above I got the following message: If builds of PostgreSQL 9 are failing and you have version 8.x installed.
So I run the following command:
ARCHFLAGS="-arch x86_64" gem install pg
and this worked for me, I hope this helps someone :)
Ok I also had this problem (psql is v 9.3.0 and ruby is v 2.1.2) and the solution that worked for me was setting the bundle config settings first:
bundle config build.pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config
This answer finally helped me figure it out: https://stackoverflow.com/a/9235107/3546680
I tried everything for hours but the following finally fixed it (I'm on OS X 10.9.4):
Install Xcode command line tools (Apple Developer site)
brew uninstall postgresql
brew install postgresql
ARCHFLAGS="-arch x86_64" gem install pg
easy step
brew install postgresql
gem install pg -v 'your version'
Similarly, after installing Mavericks bundle update was throwing an error on the pg gem, which is only used on production and not locally.
I use Brew to manage my packages and postgresql was already installed, but still I was getting the 'no pg_config' error.
The fix was to just brew uninstall postgresql, then brew install postgresql. After which I was immediately able to successfully run bundle update.
I believe the “correct” answer would be to first configure PATH correctly for Postgres.app by adding the following to ~/.profile (.zshrc or ~/.zprofile if using ZSH):
export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/latest/bin
Then open a new tab or window in terminal and install the pg gem with:
ARCHFLAGS="-arch x86_64" gem install pg
Documented here:
https://postgresapp.com/documentation/cli-tools.html
https://postgresapp.com/documentation/configuration-ruby.html
On OSX with Postgres installed in /Applications, I simply run the following command (change 0.20 & 9.4 according to your version)
gem install pg -v '0.20' -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.4/bin/pg_config
You should have :
Building native extensions with:
'--with-pg-config=/Applications/Postgres.app/Contents/Versions/9.4/bin/pg_config'
This could take a while... Successfully installed pg-0.20.
running brew update and then brew install postgresql worked for me, I was able to run the pg gem file no problem after that.
I spent a day on this and here's how I got it fixed:
I found that global value of build.pg was set to: /opt/local/lib/postgresql91/bin/pg_config
and that was not where postgres was installed.
I fixed it with replacing the value of build.pg to:
bundle config build.pg --with-pg-config=/usr/local/Cellar/postgresql/9.4.4/bin/pg_config
which is where my postgresql installation is.
Try:
gem install pg -- --with-pg-config=`which pg_config`
Solved!
I found some lack of library for PostgreSQL on the system.
Only two steps solved it:
brew install postgresql
Then run
gem install pg
For those who are not interested to use brew.
Download PostgreSQL application.
Follow the macOS default instruction to install it.
It is advisable to run PostgreSQl.
Run gem install pg -- --with-pg-config=/path/to/postgress/in/your/applications/folder/`
For example, in my machine it is
/Applications/Postgres.app/Contents/Versions/12/bin/pg_config
i got same problem and i solved
gem update --system 3.0.6

Installing PostgreSQL for Rails 3 on Mac OSX Snow Leopard - Error message

I've installed PostgreSQL using Brew (having previously tried to install using the standalone installer found on the PostgreSQL website), but am receiving the following error message when I try to bundle install:
Errno::EACCES: Permission denied - /Users/xxxxx/.rvm/gems/ruby-1.9.3-p194/gems/pg-0.14.1/.gemtest An error occurred while installing pg (0.14.1), and Bundler cannot continue. Make sure that `gem install pg -v '0.14.1'` succeeds before bundling.
I've found various potential solutions on Stackoverflow, none of which appear to fix the issue.
psql --version returns: 9.2.1
which psql returns: /usr/local/bin/psql
Anyone recognise this error, and/or have any further ideas as to how to fix it?
Failing that, I suppose I could stick with SQLite locally, and use PostgreSQL in the production environment. I assume I would need to manually make the following changes to the database.yml file (I'm about to deploy for the very first time):
production:
adapter: postgresql
encoding: unicode
database: myapp_production
pool: 5
username: myapp
password:
And, in my gemfile, include the following (note that running bundle install returns the same error, but because I'm assuming there won't be any errors with the PostgreSQL installation on the production server, I think it should still work?):
group :production do
gem 'pg'
end
EDIT: Scratch that, Webrick won't run at all if gem 'pg' is included in the gemfile.
EDIT 2: Also, when I try to run rvmsudo gem install pg, I get this:
ld: in /usr/local/lib/libssl.0.9.8.dylib, missing required architecture x86_64 in file
collect2: ld returned 1 exit status
make: *** [pg_ext.bundle] Error 1
** EDIT 3: ** Admitting defeat.
Hi folks,
Firstly, thanks for all your help.
Unfortunately, after two days, I'm going to have to admit defeat.
No matter which method I try, and whether I use the EnterpriseDB version or Homebrew-installed version of PostgreSQL, I simply cannot install the pg gem. I've tried all of the following:
install gem pg
sudo install gem pg
rvmsudo install gem pg
sudo env PATH=/library/PostgreSQL/9.2/bin:$PATH gem install pg (when using the EnterpriseDB installer)
rvmsudo env PATH=/library/PostgreSQL/9.2/bin:$PATH gem install pg (ditto)
rvmsudo env PATH=/library/PostgreSQL/9.2/bin:$PATH ARCHFLAGS="-arch x86_54" gem install
Whichever of the above methods I choose returns the following error:
ld: in /usr/local/lib/libssl.0.9.8.dylib, missing required architecture x86_64 in file
Whenever I try to install the gem via a bundle install, I get the following error:
Errno::EACCES: Permission denied - /Users/xxx/.rvm/gems/ruby-1.9.3-p194/gems/pg-0.14.1/.gemtest
An error occurred while installing pg (0.14.1), and Bundler cannot continue.
Make sure that `gem install pg -v '0.14.1'` succeeds before bundling.
I can't afford to spend more time on this, so I've bit the bullet and will probably use MySQL instead.
Thanks again,
Graeme
FINAL EDIT - Fixed! See my answer below for how I did it, as it may help others **
YES!!!!
Sorry, but I think I might leap into the air. I think I may have got it to work.
In case anyone else runs into this problem, here's what I did to get the gem to install on Snow Leopard (the process may be different for Lion):
1) Make sure you uninstall any old versions of PostgreSQL - both EnterpriseDB & Homebrew versions. For EnterpriseDB, see this Stackoverflow question/answer, and for Homebrew, simply do brew uninstall postgresql --force.
2) Do a brew install postgresql to get the Homebrew installation.
3) Now, the problem (as Chris Travers pointed out in an earlier comment - Thanks Chris!) appears to be due to OpenSSL. It seems my version (which I guess was Snow Leopard's default version, as I'd never heard of it til today) was an older version, so I had to use Homebrew to install a more up-to-date version (I also used MacPorts to uninstall the old version - not sure it's appropriate having MacPorts and Homebrew installed on the same computer, but...):
Macports: sudo port uninstall openssl
Homebrew: brew install openssl
This should update OpenSSL to the latest 64-bit version (I think?).
4) Following on from another Stackoverflow post, I did the following:
sudo gem install pg -- --with-ldflags='-L/usr/local/Cellar/openssl/0.9.8s'
Success! That seemed to work. I've still to set up a new Rails project to check everything installed OK, but bundle install causes no problems when gem 'pg' is included in my Gemfile, so fingers crossed :-)
Hope this helps others.
It looks to me like you are missing something regarding OpenSSL (whether a header file or otherwise) on your installation. I would double check the installation there. Failing that I would suggest looking into disabling SSL support on this gem however you do that. I looked over the source and it looks like it compiles against libpq which may already be able to link to OpenSSL anyway so that may not be an issue.
Here's what worked for me:
1) installing postgres gem from my console
brew install postgres
sudo env ARCHFLAGS="-arch x86_64" gem install pg
2) Then afterwards in my GemFile so I could continue to use sqlite for dev:
group :development, :test do
gem 'sqlite3'
end
group :production do
gem 'pg'
end

Resources