Here is my error log. I've been trying to do a bundle install and it asked me install mysql2. I've tried most of the things on stackoverflow and nothing seems to work for me.
I did the following
gem install mysql2 -v '0.3.18', no luck.
gem install mysql2 -v '0.3.18' -- --with-mysql-dir=/usr/local/bin/mysql
gem install mysql2 -- --with-mysql-config=/usr/local/Cellar/mysql/5.6.19/bin/mysql_config
Tried removing/changing the cflags and cxxflags in mysql_config.
None of the above attempts worked.
Anyone has a different solution for this problem? what else should I try ?
I did brew install mysql and its in /usr/local/bin/mysql,
Okay I think it has got something to do with it not being able to find the MySql header files. I'm not able to find the MySQL development files installed.
Tried doing a which mysql-devel and it gives mysql-devel not found. How do I install this? brew install does not work in this case.
Are you trying to use mysql2 as the database for Ruby on Rails? If so maybe the gem you need is "activerecord-mysql2-adapter".
Related
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).
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
I got this error
Could not find mysql2-0.3.13 in any of the sources
Run `bundle install` to install missing gems.
I tried to gem install mysql2 but without luck, it didn't fix it. I'm using wampp server and copied the libmysql.ddl to the bin folder of ruby. I also tried adding the path to the gem install just like this.
gem install mysql2 --platform=ruby -- ‘-with-mysql-lib=”C:\wamp\bin\mysql\mysql5.5.24\lib” -with-mysql-include=”C:\wamp\bin\mysql\mysql5.5.24\include”‘
Any ideas on how to fix this? THanks!
First, make sure you have mysql installed on your machine.
If you have an Ubuntu distribution, try:
sudo apt-get install libmysql-ruby libmysqlclient-dev
then try to install the gem again.
I installed mysql2 from sources like this
# i experienced some troubles with mysql2 0.3.13 installing
gem fetch mysql2 -v 0.3.12
gem install mysql2-0.3.12.gem -- ' --with-mysql-include="c:\Program Files (x86)\MariaDB 5.5\include\mysql" --with-mysql-lib="c:\Program Files (x86)\MariaDB 5.5\lib" '
But after each Gemfile updating and bundle install, bundler is installing precompiled version of mysql2 gem and it's very annoying. After manual removing precompiled gem rails app started successfully
P.S. You also need installed Ruby DevKit.
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
I'm trying to start a rails project with a postgresql database but when i try to create the db with the command:
rake db:create
I'm getting the following error message:
rake aborted!
no such file to load -- pg
I'm using mac os X so postgresql is intalled in the /Library folder. I've look around for the pg file but i could not find it and i
If you are using PostgreSQL 9 downloaded from enterprisedb you need to install the pg gem in one of the following way:
If you use rvm use:
env ARCHFLAGS="-arch x86_64" \
gem install pg -- \
--with-pg-include=/Library/PostgreSQL/9.0/include/ \
--with-pg-lib=/Library/PostgreSQL/9.0/lib/
Otherwise use:
sudo env ARCHFLAGS="-arch x86_64" \
gem install pg -- \
--with-pg-include=/Library/PostgreSQL/9.0/include/ \
--with-pg-lib=/Library/PostgreSQL/9.0/lib/
If that doesn't work, we need to know which version of OSX and which version of PostgreSQL.
make sure you have the pg gem installed.
gem install pg
or
include gem pg in your Gemfile and run bundle install if using bundler
All right. Another day, another opportunities.
I found the problem! If you want to install "gem install pg" you need to have the postgres header files on your machine. After I installed Postgres 8.3 via Macports I was also able to install the pg gem. I used this command to install the pg gem:
sudo env ARCHFLAGS='-arch i386' gem install pg
I found the solution in this blog post:
http://flux88.com/blog/installing-postgresql-for-rails-on-mac-os-x/
After reading the post and all the comments, I could resolve the problem.
For me it does not work.
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/opt/local/bin/ruby1.9 extconf.rb --with-pg-include=/Library/PostgreSQL/8.4/include/ --with-pg-lib=/Library/PostgreSQL/8.4/lib/ --with-pg-config=/Library/PostgreSQL/8.4/bin/pg_config
Using config values from /Library/PostgreSQL/8.4/bin/pg_config
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for PQconnectdb() in -lpq... no
checking for PQconnectdb() in -llibpq... no
checking for PQconnectdb() in -lms/libpq... no
Can't find the PostgreSQL client library (libpq)
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
Ruby + PostgreSQL = Pain in the ASS!
I not wondering why everybody uses mySQL instead of Postgres. With mySQL I never had so much trouble. It is easy to install and easy to use. With Postgres I have always just problems.
After hours of troubleshooting and googeling for shitty postgres ruby driver I am very pissed off. Tomorrow I will take a look to MongoDB and I hope it is less pain than Postgres!
good night!
The problem is you didn't install PostgreSQL properly.
User Brew to install PostgreSQL.
brew update
then install PostgreSQL.
brew install postgresql
Make sure you follow the instructions for PostgreSQL and that the version you installed matches the version you are using.
you can get the version by doing.
psql --version
PostgreSQL is worth learning and much more advanced than MYSQL. Used properly it will improve your Rails application.
This tutorial helped me learn.
The problem is you didn't install PostgreSQL properly.
User Brew to install PostgreSQL.
brew update
then install PostgreSQL.
brew install postgresql
Make sure you follow the instructions for PostgreSQL and that the version you installed matches the version you are using.
you can get the version by doing.
psql --version
PostgreSQL is worth learning and much more advanced than MYSQL. Used properly it will improve your Rails application.
This tutorial helped me learn.
http://railscasts.com/episodes/342-migrating-to-postgresql