Tag Archives: gem No rule to make target `/include/ruby.h’

[Solved] Ruby cannot load such file — zlib, openssl(LoadError), gem No rule to make target `/include/ruby.h’

Ruby source installation cannot load such file – zlib (LoadError) and cannot load such file – openssl (LoadError) and gem No rule to make target `/include/ruby.h’, needed by `zlib.o’. Stop. Solution

My preconditions when a problem occurs

  1. Linux version: Linux version 3.10.0-862.el7.x86_64 ([email protected]) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC)) #1 SMP Fri Apr 20 16:44:24 UTC 2018
  2. gcc version: gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
  3. Ruby version: ruby ​​2.6.5p114 (2019-10-01 revision 67812) [x86_64-linux]
  4. gem version: 3.0.6
  5. Ruby installation method: source code installation and source code is not deleted
  6. The purpose of installing Ruby and gems: Use ruby ​​to build a redis cluster

cannot load such file – zlib problem solving

the reason

  1. The zlib library is missing
  2. Ruby-zlib is missing

solve

  1. (When zlib is not installed) Download and install zlib
    • I use the source code to install, by default it is installed to /usr/local/lib, I choose to use the root user to operate
    • Install version zlib-1.2.11
      1. Download package wget http://www.zlib.net/zlib-1.2.11.tar.gz
      2. Unzip the package tar -zxvf zlib-1.2.11.tar.gz
      3. Enter the zlib source directory cd zlib-1.2.11/
      4. Configuration ./configure
      5. make make
      6. an examination make check
      7. installation make install
      8. Check whether it is successful (libz.a exists in the directory) find /usr/local/lib -name libz.a
  2. Install ruby-zlib
    • Ruby source code provides the source code, directly find the corresponding directory to install
      1. cd /root/ruby-2.6.5/ext/zlib
      2. ruby ./extconf.rb
        • If an error is reported checking for zlib.h… no or checking for deflateReset() in -lzlib… no
        • then ruby ./extconf.rb --with-zlib-dir =/usr/local/zlib
      3. make
        • If an error is reported make: *** No rule to make target /include/ruby.h', needed byzlib.o’. Stop.
        • According to the log, we know that zlib.o: $(top_srcdir)/include/ruby.h to check the source code, if there is indeed no variable value
          1. In the first line of the Makefile document, set the path of the variable top_srcdir
          2. (I adopted) Replace $(top_srcdir) with absolute/relative path
            • It is recommended to backup Makefile first
            • vim Makefile
            • : %s/$(top_srcdir)/..\/../g
            • :wq
      4. If an error was reported by make in the previous step, please modify it againmake
      5. make install

cannot load such file – openssl problem solving

the reason

  1. Openssl-devel is not installed
  2. Lack of ruby-openssl

solve

  1. (When openssl is not installed) download and install openssl
    • I use the source code installation, the default installation is /usr/local/ssl, and there is no link command
    • Installed version openssl-1.0.2t
      1. Download package wget https://www.openssl.org/source/openssl-1.0.2t.tar.gz
      2. Unzip the package tar -zxvf openssl-1.0.2t.tar.gz
      3. Enter the catalog cd openssl-1.0.2t
      4. ./config shared zlib
      5. make depend
      6. make
      7. make install
      8. Verify that the installation is successful (display version information) /usr/local/ssl/bin/openssl version -a
      9. If necessary, you can manually link the openssl command
        • First confirm that /usr/bin/openssl and /usr/include/openssl do not exist, if they exist, please backup or delete the original openssl
          • (Optional) Backup method
            • mv /usr/bin/openssl /usr/bin/openssl.bak
            • mv /usr/include/openssl /usr/include/openssl.bak
        • Link to the openssl you just installed
          • ln -s /usr/local/ssl/bin/openssl /usr/bin/openssl
          • ln -s /usr/local/ssl/include/openssl /usr/include/openssl
        • (Optional) Write ld.so.conf to record the path of the dynamic library
          • echo “/usr/local/ssl/lib” >> /etc/ld.so.conf
          • ldconfig -v
        • Verify that the link is successful openssl version -a
  2. Install ruby-openssl
    • Ruby source code provides the source code, directly find the corresponding directory to install
      1. cd /root/ruby-2.6.5/ext/openssl
      2. ruby ./extconf.rb
        • (The newly installed openssl may not be linked) Error checking for openssl.h… no or checking for deflateReset() in -openssl… no
        • then ruby ./extconf.rb --with-openssl-dir=/usr/local/ssl
      3. make
        • If an error is reported make: *** No rule to make target /include/ruby.h', needed byzlib.o’. Stop.
        • According to the log, we know that zlib.o: $(top_srcdir)/include/ruby.h to check the source code. If there is indeed no variable value, the processing method is the same as installing ruby-zlib
          1. In the first line of the Makefile document, set the path of the variable top_srcdir
          2. (I adopted) Replace $(top_srcdir) with absolute/relative path
            • It is recommended to backup Makefile first
            • vim Makefile
            • : %s/$(top_srcdir)/..\/../g
            • : wq
      4. If an error was reported by make in the previous step, please modify it againmake
      5. make install

No rule to make target /include/ruby.h', needed byzlib.o’. Stop. Solution

the reason

  1. It may be that the corresponding value of the $(top_srcdir)/include/ruby.h variable is missing

solve

  1. If an error is reported make: *** No rule to make target /include/ruby.h', needed byzlib.o’. Stop.
  2. According to the log, we know that zlib.o: $(top_srcdir)/include/ruby.h to check the source code, if there is indeed no variable value
    1. In the first line of the Makefile document, set the path of the variable top_srcdir
    2. (I adopted) Replace $(top_srcdir) with absolute/relative path
      • It is recommended to backup Makefile first
        • cp Makefile Makefile.bak
      • vim Makefile
      • : %s/$(top_srcdir)/..\/../g
      • : wq