Even I have installed ruby-dev and ruby-make but still giving same error ? how to fix the error ?
sudo gem install mechanize
Building native extensions. This could take a while...
ERROR: Error installing mechanize:
ERROR: Failed to build gem native extension.
current directory: /var/lib/gems/2.4.0/gems/unf_ext-0.0.7.5/ext/unf_ext
/usr/bin/ruby2.4 -r ./siteconf20180417-8728-15wdd1s.rb extconf.rb
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h
extconf failed, exit code 1
Gem files will remain installed in /var/lib/gems/2.4.0/gems/unf_ext-0.0.7.5 for inspection.
Results logged to /var/lib/gems/2.4.0/extensions/x86_64-linux/2.4.0/unf_ext-0.0.7.5/gem_make.out
You don't have the source code for Ruby so when it attempts to compile the gem it fails. It's looking for /usr/lib/ruby/include/ruby.h but that file isn't present on your system.
Generally, it's not a good idea to use the system version of Ruby. (for this reason, and others) You should use a Ruby manager to install Ruby into your user profile, as this will make compiling gems a lot easier.
For example, you can use RVM to install Ruby:
\curl -sSL https://get.rvm.io | bash -s stable
This will install the latest version of rvm, which you can then use to install Ruby 2.4:
rvm install 2.4
You can install nearly any version of Ruby by specifying its version, for example Ruby 2.5:
rvm install 2.5
Afterwards, running ruby will automatically run the version installed by RVM. And since it's installed in your profile, you don't need to use sudo for any operations. (and you should never use sudo when using rvm or Rubies installed by rvm)
In your case, you would then be able to run gem install mechanize successfully because it would be using the Ruby installation in your home directory that includes a copy of the source code and header files.
If for some reason you can't use RVM or don't want to use RVM, then you need to have the Ruby header files installed. The way to install these headers varies by operating system so there's no one answer I can give you. If your OS is a Debian-based version of Linux, for example, you can install the headers with:
sudo apt-get install ruby2.4-dev
More information is available in another answer on stackoverflow.
Related
I'm trying to get Compass installed on a 2020 Mac Book Pro running Big Sur (11.5.2).
When I try and run:
gem install compass
I get the error:
You don't have write permissions for the /Library/Ruby/Gems/2.6.0 directory
If I try and run:
sudo gem install compass
I get the error:
ERROR: Error installing compass:
ERROR: Failed to build gem native extension.
current directory: /Library/Ruby/Gems/2.6.0/gems/ffi-1.15.4/ext/ffi_c
I've tried installing and updating Ruby.
I've tried updating the system Ruby, but the system doesn't allow a more recent version than the below:
Updating rubygems-update
Fetching rubygems-update-3.3.3.gem
Successfully installed rubygems-update-3.3.3
Parsing documentation for rubygems-update-3.3.3
Installing ri documentation for rubygems-update-3.3.3
Installing darkfish documentation for rubygems-update-3.3.3
Done installing documentation for rubygems-update after 206 seconds
Parsing documentation for rubygems-update-3.3.3
Done installing documentation for rubygems-update after 0 seconds
Installing RubyGems 3.3.3
ERROR: While executing gem ... (Errno::EPERM)
Operation not permitted # rb_sysopen - /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/gem
% ruby -v
ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin20]
Not sure what to do or try next.
Anyone have any ideas on how to get Compass installed?
This really decomposes to two issues, as you noticed with the sudo call.
(1) You're trying to write gems to the protected directory for your system Ruby.
In most development environments, it's best to install a Ruby version manager that allows you to install multiple Rubies side-by-side for different projects. Purely subjectively, I'd recommend rbenv to manage only Ruby, or asdf to manage Ruby versions along with other languages versions. However, the question of which Ruby version manager to use is very well tread already, so you can pick the solution that's best for your needs with existing information.
(2) You're installing a gem with native extensions, which means that you need the underlying C libraries installed on your system to build correctly (assuming you're using CRuby, the default Ruby implementation). You'll need to install libffi-dev on your machine to build that gem correctly. Based on this question, it seems a simple brew install libffi should work for that.
Lastly, I'll suggest that it's idiomatic to use the bundler gem to manage gems per-project with Ruby. I'd reconsider if you really want to run this gem system-wide, or if it might vary versions across multiple projects.
I trying to set up a development environment on a new machine. Ruby seems unhappy.
sudo npm install ruby -g
+ ruby#0.6.1
updated 1 package in 0.294s
ruby -v
ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin18]
sudo gem install sass
Building native extensions. This could take a while...
ERROR: Error installing sass:
ERROR: Failed to build gem native extension.
current directory: /Library/Ruby/Gems/2.3.0/gems/ffi-1.11.1/ext/ffi_c
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby -I /Library/Ruby/Site/2.3.0 -r ./siteconf20190607-1543-ilb80e.rb extconf.rb
mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/include/ruby.h
extconf failed, exit code 1
Gem files will remain installed in /Library/Ruby/Gems/2.3.0/gems/ffi-1.11.1 for inspection.
Results logged to /Library/Ruby/Gems/2.3.0/extensions/universal-darwin-18/2.3.0/ffi-1.11.1/gem_make.out
Yes I have already installed command line tools
xcode-select --install
xcode-select: error: command line tools are already installed, use "Software Update" to install updates
I have uninstalled and reinstalled ruby. What else can I try?
This NPM package you've installed called ruby is not Ruby, but instead just something with the same name. It's not going to help with your Ruby problems. NPM is exclusively for Node.js.
To work with Ruby you'll want to install rbenv. Follow the instructions closely for ensuring your Path is set up properly.
This gives you a lot more flexibility, but most importantly the Ruby development headers that are missing from the default macOS supplied Ruby.
Pure-Ruby packages will work without development headers, but anything that has compiled extensions, like Nokogiri or apparently Ruby SASS, will require them. In that case rbenv has you covered.
I'm trying to install packetgen, a library for crafting and manipulating network packets. I followed all the instructions, and installed all the necessary libraries. However, when I ran sudo gem install packetgen
to install it on my Linux machine it raised an error:
ERROR: Error installing packetgen:
ERROR: Failed to build gem native extension.
current directory: /var/lib/gems/2.3.0/gems/pcaprub-0.12.4/ext/pcaprub_c
/usr/bin/ruby2.3 -r ./siteconf20181009-29130-us1azm.rb extconf.rb
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h
extconf failed, exit code 1
Gem files will remain installed in /var/lib/gems/2.3.0/gems/pcaprub-0.12.4 for inspection.
Results logged to /var/lib/gems/2.3.0/extensions/x86_64-linux/2.3.0 /pcaprub-0.12.4/gem_make.out [here][1]
I ran the command as sudo, but got the same error. Does anyone know what I'm doing wrong here? The link to installation instructions is here.
Don't use sudo gem install but rather it is highly recommended that you use a ruby version manager, probably RVM, for more reasons why, see 'sudo gem install' or 'gem install' and gem locations
Based on your error it looks like you're trying to use your system ruby which will likely have permission and/or library dependency issues. These are easily solved by using a version manager which has many advantages including the ability to use different ruby versions on the same system and not having to use sudo or root level installs of gems.
You can install RVM from here
Instructions on gem link you posted do say gem depends on sudo apt install libpcap-dev which is a system lib your gem needs to build. I assume you did that step already right?
I'm currently trying to build a Ruby app on a Centos 6.6 machine. There are different Ruby stacks installed through Software Collections. Please not that I do not have root on the machine, and my privileges are limited, particularly, they do not include package installation.
Native extensions do not build. It seems ruby-devel is missing, but I was told by the admin that it was correctly installed for both stacks:
dnf install rh-ruby22-ruby-devel.x86_64 ruby193-ruby-devel.x86_64 -y
Here is my problem:
bob#server ~> scl enable rh-ruby22 bash
bash-4.1$ ruby -v
ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-linux-gnu]
bash-4.1$ gem install json Building native extensions. This could take a while... ERROR: Error installing json:
ERROR: Failed to build gem native extension.
/opt/rh/rh-ruby22/root/usr/bin/ruby -r ./siteconf20150625-17536-saskmd.rb extconf.rb mkmf.rb can't find header files for ruby at /opt/rh/rh-ruby22/root/usr/share/include/ruby.h
extconf failed, exit code 1
Gem files will remain installed in ~/.gem/ruby/gems/json-1.8.3 for inspection. Results logged to ~/.gem/ruby/extensions/x86_64-linux/json-1.8.3/gem_make.out
How can I check if ruby-devel (more precisely, rh-ruby22-ruby-devel.x86_64) is properly installed?
What would be the next place to search if it's working as intended?
This is most likely because you don't have the devel libraries installed for the SCLo ruby version.
sudo yum install rh-ruby22-ruby-devel
You will need to export your library paths to get it up and running correctly.
e.g.
export PATH=/opt/rh/rh-ruby22/root/usr/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/opt/rh/rh-ruby22/root/usr/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
export MANPATH=/opt/rh/rh-ruby22/root/usr/share/man:$MANPATH
export PKG_CONFIG_PATH=/opt/rh/rh-ruby22/root/usr/lib64/pkgconfig${PKG_CONFIG_PATH:+:${PKG_CONFIG_PATH}}
# For SystemTap.
export XDG_DATA_DIRS=/opt/rh/rh-ruby22/root/usr/share${XDG_DATA_DIRS:+:${XDG_DATA_DIRS}}
After going step by step (installed both ruby and rubygems properly) to install watir-webdriver, I am facing following error:
ERROR: Error installing watir-webdriver:
ERROR: Failed to build gem native extension.
/usr/bin/ruby1.9.1 extconf.rb
<internal:lib/rubygems/custom_require>:29:in `require': no such file to load -- mkmf (LoadError)
from <internal:lib/rubygems/custom_require>:29:in `require'
from extconf.rb:4:in `<main>'
Please help me resolve this and do let me know what made this happened?
Not sure how you are installing ruby on your Ubuntu machine but may I recommend the Ruby Version Manager.
https://rvm.io/
this will allow you to install different versions of ruby on your machine and switch between them as well as gems etc.
here is a quick guide I wrote for installing watir webdriver in Ubuntu via RVM:
Ubuntu requires the use of a Ruby Version Manager. To do this we will need to first install both the Curl package and Git-core.
To do this use the following command:
sudo apt-get install curl git-core
Upon success we will need to download the Ruby Version Manager application. This application allows us to install multiple versions of ruby as well as switch between. It also provides a Gem manger. Recommended to Google to read up on the commands and features within RVM. To install RVM use the following:
bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer )
We can also install packages within RVM and we will require the use of openSSL:
rvm pkg install openssl
Then installing Ruby itself:
rvm install 1.9.3-p125 --with-openssl-dir=$rvm_path/usr
Best to test this is all working with:
irb
When all clear we can install the Gem, we need to install it within the RVM with the follow:
rvm do gem install watir-webdriver
If installed correctly we should be able to use watir to drive firefox which is already installed on ubuntu.
I am not Linux/Ubuntu expert but the error message says you do not have build tools installed.