If you are facing “Failed to build gem native extension” error while installing mysql and pg gem on ubuntu, which might look like

Gem Install Issue

then you need to install the below mentioned packages for the same :

For mysql gem :

sudo apt-get install libmysqlclient-dev

For pg gem :

sudo apt-get install libpq-dev

After installing the above packages, try installing the gem again. Hopefully, this time, it will get installed successfully.