Failing to load Ruby's tk on Ubuntu - ruby

I am really new to Ruby and I need to use this library for a specific GUI project. I am using:
Ubuntu 18.04.5 LTS;
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux-gnu]
My problem is similar to the one this person described a few months ago. I have tried the solution posted on that SO page which is based on this blog post.
After running:
sudo apt-get install tcl8.5-dev tk8.5-dev
And:
sudo gem install tk
I get the following error message:
Building native extensions. This could take a while...
ERROR: Error installing tk:
ERROR: Failed to build gem native extension.
current directory: /var/lib/gems/2.5.0/gems/tk-0.4.0/ext/tk
/usr/bin/ruby2.5 -r ./siteconf20210424-11015-1mre8d0.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.5.0/gems/tk-0.4.0 for inspection.
Results logged to /var/lib/gems/2.5.0/extensions/x86_64-linux/2.5.0/tk-0.4.0/gem_make.out
This error message is different from the one described in the blog post which is:
$ gem install tk
Building native extensions. This could take a while...
ERROR: Error installing tk:
ERROR: Failed to build gem native extension.
# ...
Search tcl.h
checking for tcl.h... no
Search tk.h
checking for tk.h... no
Search Tcl library............*** extconf.rb failed ***
# ...
Warning:: cannot find Tcl library. tcltklib will not be compiled (tcltklib is disabled on your Ruby. That is, Ruby/Tk will not work). Please check configure options.
Can't find proper Tcl/Tk libraries. So, can't make tcltklib.so which is required by Ruby/Tk.
If you have Tcl/Tk libraries on your environment, you may be able to use them with configure options (see ext/tk/README.tcltklib).
The gem provides many switches for specifying the configuration parameters, however, the related parameters (--with-tk-lib and --with-tcl-lib) don’t yield the desired effect (actually, any effect at all).
The workaround, originally found in a Ruby forum is to symlink the libraries to the paths where the extension expects
Then, after running:
sudo ln -s /usr/lib/x86_64-linux-gnu/tcl8.5/tclConfig.sh /usr/lib/
sudo ln -s /usr/lib/x86_64-linux-gnu/tk8.5/tkConfig.sh /usr/lib/
sudo ln -s /usr/lib/x86_64-linux-gnu/libtcl8.5.so.0 /usr/lib/
sudo ln -s /usr/lib/x86_64-linux-gnu/libtk8.5.so.0 /usr/lib/
I get this (probably because I tried the same steps before):
ln: failed to create symbolic link '/usr/lib/libtk8.5.so.0': File exists
Finally, running the last step does not work:
sudo gem install tk
And the terminal returns the following error message:
Building native extensions. This could take a while...
ERROR: Error installing tk:
ERROR: Failed to build gem native extension.
current directory: /var/lib/gems/2.5.0/gems/tk-0.4.0/ext/tk
/usr/bin/ruby2.5 -r ./siteconf20210424-21301-8u83wl.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.5.0/gems/tk-0.4.0 for inspection.
What should I do?
Thanks in advance.

This blog post solved the problem.
After running:
sudo apt install tk-dev
And installing Ruby/Tk gem:
gem install tk -- --with-tcltkversion=8.6 \
--with-tcl-lib=/usr/lib/x86_64-linux-gnu \
--with-tk-lib=/usr/lib/x86_64-linux-gnu \
--with-tcl-include=/usr/include/tcl8.6 \
--with-tk-include=/usr/include/tcl8.6 \
--enable-pthread
Everything was solved.

Related

Gem will not install sqlite3 despite sqlite3 being installed (Mac)

I'm trying to install Ruby (3.2.0) (and Rails [7.0.4]) on an Intel Mac (OS 12.6). I'm running into issues with sqlite3 — no surprise. My current error message is this:
package configuration for /usr/local/lib/ruby/gems/3.2.0/gems/sqlite3-1.5.4/ports/x86_64-apple-darwin21.6.0/sqlite3/3.40.0/lib/pkgconfig/sqlite3.pc is not found
When I enter gem install sqlite3 I get the following ugly error message:
Building native extensions. This could take a while...
ERROR: Error installing sqlite3:
ERROR: Failed to build gem native extension.
current directory: /usr/local/lib/ruby/gems/3.2.0/gems/sqlite3-1.5.4/ext/sqlite3
/usr/local/opt/ruby/bin/ruby -I /usr/local/lib/ruby/site_ruby/3.2.0 extconf.rb
Building sqlite3-ruby using packaged sqlite3.
Extracting sqlite-autoconf-3400000.tar.gz into tmp/x86_64-apple-darwin21.6.0/ports/sqlite3/3.40.0... OK
Running 'configure' for sqlite3 3.40.0... OK
Running 'compile' for sqlite3 3.40.0... OK
Running 'install' for sqlite3 3.40.0... OK
Activating sqlite3 3.40.0 (from /usr/local/lib/ruby/gems/3.2.0/gems/sqlite3-1.5.4/ports/x86_64-apple-darwin21.6.0/sqlite3/3.40.0)...
Could not configure the build properly (pkg_config). Please install either the `pkg-config` utility or the `pkg-config` rubygem.
*** 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.
Provided configuration options:
[insert long list of options...]
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/usr/local/lib/ruby/gems/3.2.0/extensions/x86_64-darwin-21/3.2.0/sqlite3-1.5.4/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in /usr/local/lib/ruby/gems/3.2.0/gems/sqlite3-1.5.4 for inspection.
Results logged to /usr/local/lib/ruby/gems/3.2.0/extensions/x86_64-darwin-21/3.2.0/sqlite3-1.5.4/gem_make.out
I've been through many iterations of solutions found across the interwebs (changing permissions, installing pkg-config per the error message, changing $PATH in .zshrc, installing sqlite binary packages, modifying the Gemfile, total uninstalls of both, and restarts) to no avail.
The Homebrew-installed sqlite3 is working properly. which sqlite3 produces
/usr/local/opt/sqlite3/bin/sqlite3
Happy to provide any more relevant information that's helpful. Any guidance appreciated!
If you do not have pkg-config installed, you should install to proceed
You can check it using:
$ which pkg-config
If not found, install it:
$ curl https://pkg-config.freedesktop.org/releases/pkg-config-0.28.tar.gz -o pkgconfig.tgz
$ tar -zxf pkgconfig.tgz && cd pkg-config-0.28
$ ./configure && make install
I'm just following this page

Error: Failed to build gem native extension building listen gem

I have been trying to run gem install listen and I saw this error below.
ERROR: Error installing listen:
ERROR: Failed to build gem native extension.
current directory: /var/lib/gems/2.5.0/gems/ffi-1.11.3/ext/ffi_c
/usr/bin/ruby2.5 -r ./siteconf20200106-9209-e0kdmx.rb extconf.rb
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h
extconf failed, exit code 1
"can't find header files for ruby" explains the issue best. Make sure to install Ruby developer libraries.
Depending on your OS and package manager, try
sudo apt-get install ruby-dev
or
sudo yum install ruby-dev
or
sudo apk add ruby-dev
or
xcode-select --install
Also, please check out Error while installing json gem 'mkmf.rb can't find header files for ruby' and similar proposed solutions.

Rubocop installing error: Failed to build gems

I'm currently having this problem when i try to install Rubocop(I can't install nokigiri either):
~$ sudo gem install rubocop
Building native extensions. This could take a while...
ERROR: Error installing rubocop:
ERROR: Failed to build gem native extension.
current directory: /var/lib/gems/2.5.0/gems/jaro_winkler-1.5.2/ext/jaro_winkler
/usr/bin/ruby2.5 -r ./siteconf20190320-24856-1cn9xqz.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.5.0/gems/jaro_winkler-1.5.2 for inspection.
Results logged to /var/lib/gems/2.5.0/extensions/x86_64-linux/2.5.0/jaro_winkler-1.5.2/gem_make.out
I've tried others solutions, but none worked.
Anyone knows why i'm getting this error ?
Thx
You need to install development headers for ruby 2.5, you don't have a development environment installed:
sudo apt-get install ruby2.5-dev
May also be called -devel depending on your packaging system.

ruby- packetgen installation gives gem install error

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?

cannot install sqlite3 using gem

I'm trying to install Metasploit on my Raspberry Pi 2.
But when I try to execute this command:
gem install wirble sqlite3 bundler
I get this error:
Successfully installed wirble-0.1.3 Parsing documentation for
wirble-0.1.3 Done installing documentation for wirble after 2 seconds
Building native extensions. This could take a while... ERROR: Error
installing sqlite3:
ERROR: Failed to build gem native extension.
/usr/bin/ruby2.1 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.1.0/gems/sqlite3-1.3.13 for inspection. Results logged
to
/var/lib/gems/2.1.0/extensions/arm-linux/2.1.0/sqlite3-1.3.13/gem_make.out
Successfully installed bundler-1.15.4 Parsing documentation for
bundler-1.15.4 Done installing documentation for bundler after 73
seconds 2 gems installed
The system is missing ruby dev files. If you are using Debian
sudo apt-get install ruby-dev
should do the work.
Install ruby-dev using your package managers. (package name may differ across different linux distros)

Resources