Error setting up Ruby on Rails - ruby-on-rails

Following this guide, I'm attempting to set up Ruby on Rails using Amazon's EC2. For my instance I've selected "Basic 32-bit Amazon Linux AMI 2010.11.1 Beta". I have ruby, sqlite, and rubygems installed. I'm on step 3.3 of the linked guide which is to run the following command
bundle install
The result is the following. I'm sure I've just missed something, but I'm at a loss. Any suggestions?
Installing sqlite3 (1.3.3) with native extensions /usr/lib/ruby/site_ruby/1.8/rubygems /installer.rb:529:in `build_extensions': ERROR: Failed to build gem native extension (Gem::Installer::ExtensionBuildError)
/usr/bin/ruby extconf.rb
mkmf.rb can't find header files for ruby at /usr/lib/ruby/ruby.h
Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/sqlite3-1.3.3 for inspection.
EDIT: Following the suggestion below to install ruby-devel, I now get this error in addition to the original one.
Installing sqlite3 (1.3.3) with native extensions /usr/lib/ruby/site_ruby/1.8/rubygems/installer.rb:529:in `build_extensions':
ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)
/usr/bin/ruby extconf.rb
checking for sqlite3.h... no
sqlite3.h is missing. Try 'port install sqlite3 +universal'
or 'yum install sqlite3-devel' and check your shared library search path (the
location where your sqlite3 shared library is located).
But when I try to run
yum install sqlite-devel
I'm told:
Package sqlite-devel-3.6.20-1.6.amzn1.i386 already installed and latest version
Nothing to do

In addition to the packages above, mas sure you have gcc and make installed.
They are needed to build the gems you are installing in addition to the development libraries.

Try to install the libsqlite3-dev before
$ sudo apt-get install libsqlite3-dev
and retry to install the gem after
$ gem install sqlite3-ruby

This worked for me:
yum install ruby-devel
yum install sqlite-devel
NOT sqlite3-devel

Venturing a guess here, but you might be missing a few development packages. Try running:
yum install ruby-devel sqlite3-devel

Related

Unable to install gem - Failed to build gem native extension - cannot load such file -- mkmf (LoadError)

Ruby 1.9.3
The part of Gemfile
#...............
gem "pony"
gem "bcrypt-ruby", :require => "bcrypt"
gem "nokogiri"
#..................
When I'm trying to install gems, I get an error
alex#ubuntu:~/$ bundle
Fetching gem metadata from http://rubygems.org/.........
Fetching gem metadata from http://rubygems.org/..
Enter your password to install the bundled RubyGems to your system:
#####............................................................
Installing bcrypt-ruby (3.0.1) with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/usr/bin/ruby1.9.1 extconf.rb
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- mkmf (LoadError)
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from extconf.rb:36:in `<main>'
Gem files will remain installed in /home/alex/.bundler/tmp/5526/gems/bcrypt-ruby-3.0.1 for inspection.
Results logged to /home/alex/.bundler/tmp/5526/gems/bcrypt-ruby-3.0.1/ext/mri/gem_make.out
An error occurred while installing bcrypt-ruby (3.0.1), and Bundler cannot continue.
Make sure that `gem install bcrypt-ruby -v '3.0.1'` succeeds before bundling.
Then I'm doing this
sudo gem install bcrypt-ruby -v '3.0.1'
Building native extensions. This could take a while...
ERROR: Error installing bcrypt-ruby:
ERROR: Failed to build gem native extension.
/usr/bin/ruby1.9.1 extconf.rb
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- mkmf (LoadError)
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from extconf.rb:36:in `<main>'
Gem files will remain installed in /var/lib/gems/1.9.1/gems/bcrypt-ruby-3.0.1 for inspection.
Results logged to /var/lib/gems/1.9.1/gems/bcrypt-ruby-3.0.1/ext/mri/gem_make.out
and getting an error as well.
What did I miss?
There are similar questions:
`require': no such file to load -- mkmf (LoadError)
Failed to build gem native extension (mkmf (LoadError)) - Ubuntu 12.04
Usually, the solution is:
sudo apt-get install ruby-dev
Or, if that doesn't work, depending on your ruby version, run something like:
sudo apt-get install ruby1.9.1-dev
Should fix your problem.
Still not working? Try the following after installing ruby-dev:
sudo apt-get install make
For WSL (Windows Subsystem for Linux) you need install build-essential package:
sudo apt install build-essential
Just finished a 2 hour wild goose chase trying to solve this. None of the posted answers worked for me. Im on a Mac (Mojave Version 10.14.6, Xcode Version 11.3).
It turns out the ruby file headers were missing so i had to run open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
That didnt work for me at first because the version of CommandLineTools i had installed did not have the "Packages" folder. So i uninstalled and reinstalled like this:
rm -rf /Library/Developer/CommandLineTools
xcode-select --install
Then i ran the previous command again:
open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
After install the error was fixed!
I had the same issue trying to install jquery-rails. The fix was
sudo apt-get install zlibc zlib1g zlib1g-dev
For MacOS users:
Just do this and easily it will solve your problem:
brew install cocoapods
In case anyone in the future had this problem, I'm using a Mac and just had to install the Command Line Tools using 'xcode-select --install'
I found that I needed to install another version of ruby. So running the command
$ sudo apt-get install ruby1.9.1-dev
and then attempt to install the extension
If you run into issues where it is telling you that you don't have g++ you can run the following command to install it
$ sudo apt-get install g++
Make sure ruby-dev is installed
Make sure make is installed
If you still get the error, look for suggested packages. If you are trying to install something like gem install pg you will also need to install the lib libpq-dev (sudo apt-get install libpq-dev).
I created a small hackMD to install cocoapods on MacOS 10.15 (Catalina) and 11 (Big Sur)
https://hackmd.io/#sBJPlhRESGqCKCqV8ZjP1A/S1UY3W7HP
Installing Cocoapods on MacOS Catalina(MacOS 10.15.X) and Big Sur (MacOS 11)
Make sure you have xcode components are installed.
Download 'Command Line Tools' (about 500MB) directly from this link (Requires you to have apple account)
https://developer.apple.com/downloads/index.action
Install the downloaded file
Click on Install
Install COCOAPODS files in terminal
sudo gem install -n /usr/local/bin cocoapods
This worked for me.
bundle config --global build.snappy --with-opt-dir="$(brew --prefix snappy)"
It also helps to ensure libmysqlclient-dev is installed (Ubuntu 14.04)
What ended up working for me after a few hours of pain..
if you're running brew..
brew install ruby
in the terminal output/log, identify the path where ruby was installed, brew suggests 'You may want to add this to your PATH', so that's what we'll do. For example, mine is
/usr/local/lib/ruby/gems/3.0.0/bin
Add this to your path by running (omitting braces)
echo 'export PATH"{the_path_you_found_above}:$PATH"' >> ~/.bash_profile
then update your environment by running
source ~/.bash_profile
now, try running your install, i.e.,
sudo gem install middleman
If you are a mac user you must need to update the clang version being used
I burnt hours searching this and installed uninstalled xcode commandline tools but it didn't help.
I ran gcc -v and Apple clang version 11.0.0 (clang-1100.0.33.8 was the output.
Then I ran xcode-select -s /Library/Developer/CommandLineTools/ and clang version was updated to Apple clang version 12.0.0 (clang-1200.0.32.29).
bundle install was successful after that.
I hope this may help.
I was making a word search app and I had to install cocoapods and after formatting my mac and reinstalling xcode, I still got the error when I wanted to install cocoapods.
And the solution for this was the following:
It looks like CocoaPods 1.9.0, the latest version as of this writing, depends on a newer version of Ruby than 2.3.7. But macOS Mojave only includes Ruby 2.3.7, so you have a few different options.
Upgrade to macOS Catalina and get Ruby 2.6.3
Use Ruby Version Manager to install a newer version of Ruby
Install an older version of CocoaPods
sudo gem install cocoapods -v 1.8.4
I did 3:
sudo gem install cocoapods -v 1.8.4
In Mac, for me this works:
CONFIGURE_OPTS="--enable-shared" rbenv install 2.2.2
After some search for a solution, it turns out the -dev package is needed, not just ruby1.8. So if you have ruby1.9.1 doing
sudo apt-get install ruby1.9.1-dev
or to install generic ruby version, use (as per #lamplightdev comment):
sudo apt-get install ruby-dev
should fix it.
Try to locate mkmf to see if the file is actually there.
first set your Xcode version on the terminal:
sudo xcode-select -switch /Applications/Xcode.app
then install:
sudo gem install cocoapods

ERROR: Error installing rails: ERROR: Failed to build gem

I'm setting up servers. I'm installing rails on an Amazon Linux
Installed List: ruby, development tools, gems, zlib-devel, readline-devel.
I'm trying to install rails and now I'm stuck here
$ sudo gem install rails Building native extensions. This could take
a while... ERROR: Error installing rails: ERROR: Failed to build gem
native extension.
/usr/bin/ruby extconf.rb mkmf.rb can't find header files for ruby at /usr/lib/ruby/ruby.h
Gem files will remain installed in
/usr/lib64/ruby/gems/1.8/gems/json-1.6.3 for inspection. Results
logged to
/usr/lib64/ruby/gems/1.8/gems/json-1.6.3/ext/json/ext/parser/gem_make.out
Is there a problem with this json library?
You need to install the following
yum install ruby-devel
yum install make
yum install gcc
You should be using Ruby 1.9.x, to upgrade Ruby:
sudo yum install ruby19
and also
sudo yum install ruby19-devel
sudo yum install make
sudo yum install gcc
If you've installed rvm, make sure to use rvm gem install rails
THe problem has nothing to do with RVM. The problem is you need ruby source header files. Compile ruby from source(RVM does that) or install the appropiate headers for your ruby version.
What is amazon linux(there is not such thing) ? is it ubuntu or what ?
How did you installed ruby ? what does ruby -v says ?

RoR install: Run 'bundle install' not working?

While trying to run a first project on Ubuntu 10.10 I got this:
antonio#antonio-desktop:~/Documents/tickets$./script/rails server
Could not find gem 'sqlite3 (>= 0)' in any of the gem sources listed in your Gemfile.
Run `bundle install` to install missing gems.
Well, afterwards I write:
antonio#antonio-desktop:~/Documents/tickets$ bundle install
and get this in the middle of the installation process:
/usr/bin/ruby1.8 extconf.rb
checking for sqlite3.h... no
sqlite3.h is missing. Try 'port install sqlite3 +universal'
or 'yum install sqlite3-devel' and check your shared library search path (the
location where your sqlite3 shared library is located).
*** 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.
So, I tried this:
sudo yum install sqlite3-devel
And got this:
Setting up Install Process
No package sqlite3-devel available.
Nothing to do
Why? I'm running Rails 3.1, btw.
try: sudo apt-get install libsqlite3-dev
Since you're using yum, I went ahead and guessed that you're on Fedora. I then Googled "fedora sqlite3" and found a blog post that recommends this:
sudo yum install sqlite-devel
Sounds like the gem doesn't have the package name quite right. Give this one a go :)

Nokogiri installation fails -libxml2 is missing

I always worked my way around Nokogiri installation issues by following the documentation in the "Installing Nokogiri" tutorial.
But this time, even after installing all the dependencies, Nokogiri hasn't been installed. I get the following error:
libxml2 is missing. please visit <http://nokogiri.org/tutorials/installing_nokogiri.html>
I tried installing it by specifying the libxml2 and libxslt directories:
sudo gem install nokogiri -- --with-xml2-include=/usr/include/libxml2 --with-xml2-lib=/usr/lib --with-xslt-dir=/usr/
but it returned the same error.
I followed all the other related Stack Overflow articles and none helped. Does anyone have a solution?
You may actually need to install both of these packages
sudo apt-get install libxslt-dev libxml2-dev
First, install the dependencies:
sudo apt-get install libxslt-dev libxml2-dev
If you still receive the error, you may be missing a compiler toolchain:
sudo apt-get install build-essential
You'll get the "libxml2 is missing" error if you're missing a build toolchain (at least I ran into this issue on Debian Lenny).
The Nokogiri build test-compiles a libxml2 header file to verify that it is present, however, it doesn't differentiate between "libxml2 is missing" and "a compiler to test libxml2 is missing".
In Mac OS X (Mavericks), installing the libraries with brew and setting NOKOGIRI_USE_SYSTEM_LIBRARIES=1 before installing the gem did the trick for me.
Summarising:
If previously installed, uninstall the gem:
gem uninstall nokogiri
Use Homebrew to install libxml2, libxslt and libiconv:
brew install libxml2 libxslt libiconv
Install the gem specifying the paths to the libraries to be linked against:
NOKOGIRI_USE_SYSTEM_LIBRARIES=1 gem install nokogiri -- --use-system-libraries --with-iconv-dir="$(brew --prefix libiconv)" --with-xml2-config="$(brew --prefix libxml2)/bin/xml2-config" --with-xslt-config="$(brew --prefix libxslt)/bin/xslt-config"
I just had the same issue on Fedora 13. After a frustrating and unsuccessful search to make
gem install nokogiri
work for me, I was able to install it and get around the libxml2 error via yum.
Simply install the gem via yum instead of the gem command:
su
yum search rubygem-nokogiri #this find the proper package name
yum install rubygem-nokogiri.i686
This helped me find the right answer for Fedora and, as I am using RVM for Ruby package management,
yum install rubygem-nokogiri
will pull in all the Ruby gems and dependencies into the system, not into my RVM environment, and in my experience that leads to a very frustrating and humbling experience.
So, taking your find of the Nokogiri yum gem you can use:
yum provides rubygem-nokogiri
and get a list of the dependencies for rubygem-Nokogiri which showed me the libraries that were missing. After that I ran:
yum install libxml2-devel libxslt libxslt-devel
Now Nokogiri compiles in Fedora and Nokogiri installs. D'oh!, we need the headers to compile Nokogiri from the devel libraries.
In Mac OS X (Mavericks) if none of these solutions work, try:
ARCHFLAGS="-arch x86_64" gem install nokogiri
or
ARCHFLAGS="-arch i386" gem install nokogiri
depending on your system's architecture.
You usually need development files for building gems. Try:
sudo apt-get install libxslt-dev libxml2-dev
(I just saw that Eric suggested the same in a comment.)
I was able to get this installed with Chocolatey, Windows 8.1 x64, and DevKit x64.
cinst libxml2
cinst libxslt
cinst libiconv
gem install nokogiri --
--with-xml2-include=C:\Chocolatey\lib\libxml2.2.7.8.7\build\native\include
--with-xml2-lib=C:\Chocolatey\lib\libxml2.redist.2.7.8.7\build\native\bin\v110\x64\Release\dynamic\cdecl
--with-iconv-include=C:\Chocolatey\lib\libiconv.1.14.0.11\build\native\include
--with-iconv-lib=C:\Chocolatey\lib\libiconv.redist.1.14.0.11\build\native\bin\v110\x64\Release\dynamic\cdecl
--with-xslt-include=C:\Chocolatey\lib\libxslt.1.1.28.0\build\native\include
--with-xslt-lib=C:\Chocolatey\lib\libxslt.redist.1.1.28.0\build\native\bin\v110\x64\Release\dynamic
You'll have to verify the version number in the paths are correct.
You may possibly need to add Microsoft's NuGet repository:
-Source "https://go.microsoft.com/fwlink/?LinkID=230477"
It will be:
sudo yum install -y libxml2 libxml2-devel
on RHEL servers.
At macOS none of above/below had really worked for me until I explicitly provided XCode libxml2 path to --with-xml2-include.
gem install nokogiri -- --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/libxml2 --use-system-libraries
I was able to install Nokogiri 1.6.5 on Fedora 20 by doing:
export NOKOGIRI_USE_SYSTEM_LIBRARIES=true
Then running:
gem install nokogiri
For anyone else experiencing this issue, I solved it by running this command within the project directory
gem install nokogiri -- --use-system-libraries
Update: I ran into this again and tried just updating the gem which worked for me...
gem update nokogiri
Have you tried installing libxml2? Not from rubygems, but via the standard install process for your operating system. On Ubuntu/Debian for example:
sudo apt-get install libxml2
On any recent version of OS X it should already be installed.
For OSX users, if you've had success installing Nokogiri before, yet are getting errors installing it on, say, using a new version of Ruby that you've added and that error that includes a message like:
The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
This could be indicative of a XCode upgrade having happened via the App Store, either manually or automatically, and you not having opened it since that time.
If so, you should be able to open XCode, agree to the new license, and then install Nokogiri successfully.
On Mac OS X Yosemite my mistake was that I tried to use sudo gem install when it's a rule of thumb to not use superuser privileges when installing gems.
In my case it tried to modify the system installation of Ruby, and that's not a good idea. I installed rbenv, installed Ruby 2.2.2 thru it and set it as global, which is a term from rbenv's documentation. After that Nokogiri could install itself with a simple
gem install nokogiri
No hacks or workarounds were necessary, just a properly set environment; Nokogiri does the rest perfectly.
Was able to install vagrant-awe by following the above post but using the command as follow:
NOKOGIRI_USE_SYSTEM_LIBRARIES=1 vagrant plugin install vagrant-aws
For Windows x64:
gem inst nokogiri --pre --platform ruby
For more information check this thread: https://github.com/sparklemotion/nokogiri/issues/864
I was able to install Nokogiri by running the following packages:
$ dnf group install "C Development Tools and Libraries"
$ dnf install ruby-devel libxml2-devel patch
=== TLDR ===
As the instructions state, build Ruby with the latest clang compiler, or at least the same version that Rubygems will use to compile Nokogiri's native extensions libxml and libxsl.
If using RVM, building from source with the --with-ggc=clang flag was what did it for me:
rvm install 2.2 --with-gcc=clang
Replace 2.2 with whatever version you want. --with-gcc=clang ensures RVM builds from source and uses clang to do so; otherwise RVM may a pre-built binary Ruby, which is what tripped me up.
Then, install Nokogiri as normal using Bundler or Rubygems.
=== IN DEPTH ===
I struggled with this for a while. gem install nokogiri gave me:
checking for xmlParseDoc() in libxml/parser.h... no
checking for xmlParseDoc() in -lxml2... no
checking for xmlParseDoc() in -llibxml2... no
Digging into mkmf.log I saw:
conftest.c:15:27: error: too few arguments to function call, single argument 'cur' was not specified
int t(void) { xmlParseDoc(); return 0; }
Nokogiri supplies its own libxml and libxsl (as of 1.6.4). The signature defined in Nokogiri's local copy of parser.h (found under the gem install directory) is:
xmlParseDoc (const xmlChar *cur);
So I was at a loss as to how the method call in the hermetically sealed conftest.c file usage couldn't match up with the header file for parser.h.
When I realized I had probably installed a binary Ruby I removed and reinstalled using --with-gcc=clang (to force compilation and use clang) and the problem was solved:
rvm uninstall 2.2
rvm install 2.2 --with-gcc=clang
gem install nokogiri
I'm not exactly sure why that works as the system libxml header /usr/include/libxml2/libxml/parser.h has the same signature as Nokogiri's local copy.
It's weird, but it worked. Just make sure you compile a Ruby with clang.
gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.7.8/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.7.8/lib --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26 --with-iconv-include=/usr/local/Cellar/libiconv/1.14/include --with-iconv-lib=/usr/local/Cellar/libiconv/1.14/lib
Change your version with it.

How to install sqlite3 gem on EC2?

When I tried to:
sudo yum install ruby-devel sqlite3-devel
Amazon EC2 returns:
Loaded plugins: fastestmirror, priorities, security
Loading mirror speeds from cached hostfile
Setting up Install Process
Package ruby-devel-1.8.7.330-1.5.amzn1.i686 already installed and latest version
No package sqlite3-devel available.
Nothing to do
Any help will be appreciated.
UPDATE:
sudo gem install sqlite3-ruby
returns
Building native extensions. This could take a while...
ERROR: Error installing sqlite3-ruby:
ERROR: Failed to build gem native extension.
/usr/bin/ruby extconf.rb
checking for sqlite3.h... no
sqlite3.h is missing. Try 'port install sqlite3 +universal'
or 'yum install sqlite3-devel' and check your shared library search path (the
location where your sqlite3 shared library is located).
*** 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.
sudo yum install sqlite3-devel should be:
sudo yum install sqlite-devel
On my Ubuntu box, I installed the following two libraries, plus the gem, in the following order:
sudo apt-get install libsqlite3-dev
sudo apt-get install sqlite3 # this installs several tools, including the command-line utility
sudo gem install sqlite3-ruby # this is going to spit out a bunch of errors, but you may be able to ignore them

Resources