Reputation: 169
I'm trying to create a project with mysql as a database, ran command
rails new project_name -d mysql
got the following errors
Could not find gem 'mysql2 (~> 0.5)' in locally installed gems. rails importmap:install
Could not find gem 'mysql2 (~> 0.5)' in locally installed gems. Run bundle install
to install missing gems.
rails turbo:install stimulus:install Could not find gem 'mysql2 (~> 0.5)' in locally installed gems.
Run bundle install
to install missing gems. "
so i ran
bundle install
but it fails and at the end it tells me
An error occurred while installing mysql2 (0.5.4), and Bundler cannot continue
full error https://pastebin.com/jiX7V0Z0
I'm running windows (all answers I found were for linux or mac), any help is appreciated
Edit : as Christos-Angelos Vasilopoulos mentioned, answer in this issue worked https://github.com/brianmario/mysql2/issues/1210#issuecomment-965862944
what I did was the first two steps
1 - Start a cmd terminal and run ridk explicitely by running:
c:\your path to Ruby31-x64\ridk_use\ridk.cmd enable
.
This gives you the right environment to do the rest.
2 - From that cmd, run
gem install mysql2 --platform=ruby -- --with-mysql-dir=c:/your path to Ruby31-x64/msys64/mingw64
(no particular quote was neeeded and I used forward slashes).
Upvotes: 3
Views: 14423
Reputation: 17
please try:
gem install mysql2 -v '0.5.4' -- --with-openssl-dir=$(brew --prefix [email protected]) --with-ldflags=-L$(brew --prefix zstd)/lib
Upvotes: 0
Reputation: 5861
using: ruby -v= 3.2.2 & Rails -v= 7.1.3.3
sudo apt-get install libmysqlclient-dev
Upvotes: 2
Reputation: 940
It is an open issue with mysql2 though there is a workaround. Check this thread from GitHub. This comment is the thing you need to resolve the problem.
Upvotes: 3
Reputation: 176
For those on Almalinux/RH/CentOS/Rocky: you can just install the gems via dnf:
sudo yum install rubygem-mysql2
Dit the trick for me. There are a lot of more gems available, just search with
sudo dnf search ruby
Upvotes: 0
Reputation: 618
I run into similar issues installing mysql2 when running bundle install
in Ubuntu. I solved the problem by installing the following dependencies. sudo apt-get install libmysqlclient-dev
.
This could be helpful for Linux users.
Upvotes: 2
Reputation: 1
after install rails on your Windows, download mysql 5.5 32bits from following link and install. https://dev.mysql.com/downloads/mysql/5.5.html (I downloaded 'Windows (x86, 64-bit), ZIP Archive' and pasted it to my C drive as mysqlconn. You can use MSI Installer and configure Add Mysql Bin Folder to PATH box).
After that install the gem in a command window by using following command:
gem install mysql2 -- '--with-mysql-lib="C:\mysqlconn\lib" --with-mysql-include="C:\mysqlconn\include"'
Then copy the libmysql.dll found in C:\mysqlconn\lib to your ruby bin folder C:\Ruby32-x64\bin
Upvotes: 0