-
Notifications
You must be signed in to change notification settings - Fork 12
Home
If you use gem for installing packages and you get
ERROR: Loading command: install (LoadError)
cannot load such file -- zlib
ERROR: While executing gem ... (NameError)
uninitialized constant Gem::Commands::InstallCommand
install zlib libraries before installing ruby with ruby-build. Or just install ruby again after installing zlib
Ubuntu:
sudo apt-get install zlib1g-dev
Install libreadline-dev
first before running ruby-build
sudo apt-get install libreadline-dev
The system Ruby creates a /etc/gemrc
file which contains --user-install
as a default flag so that pacman
-managed gems are not mixed up with externally installed gems. This file is parsed by all gem
commands, so your rubies will not be self-contained when you run gem install
, which may or may not (e.g when using rbenv) be what you want.
When you try to install a gem, this typically results in a warning like:
WARNING: You don't have ${HOME}/.gem/ruby/1.8/bin in your PATH,
gem executables will not run.
All that is needed is to commend out the gem: --user-install
line.
Ruby 1.8.7 patchlevel 302 (and below) has a known compiler bug, however will complete the rbenv install process. This bug will cause a segmentation fault whenever a SSL connection is opened.
To fix this, pass in the following compiler flags to the ruby-build process:
$ CFLAGS="-O2 -fno-tree-dce -fno-optimize-sibling-calls" rbenv install 1.8.7-p302
Ruby needs to be patched to build with those more modern compilers.
For 1.8.7 you need to add the following hook to the relevant ruby-build definition:
before_install_package() {
(
patch -p1 <<-"END_PATCH"
From a9936cf3621b2e34ea44abaabd9a4a3dbef37433 Mon Sep 17 00:00:00 2001
From: Reza Jelveh
Date: Thu, 15 Sep 2011 18:51:39 +0200
Subject: [PATCH] archlinux patch
---
ext/dl/depend | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/ext/dl/depend b/ext/dl/depend
index fba3df7..0830ffa 100644
--- a/ext/dl/depend
+++ b/ext/dl/depend
@@ -32,15 +32,15 @@ handle.o: dl.h
call.func: $(srcdir)/mkcall.rb ./dlconfig.rb
@echo "Generating call.func"
- @$(RUBY) $(srcdir)/mkcall.rb > $@
+ @$(RUBY) $(srcdir)/mkcall.rb | tee $@
callback.func: $(srcdir)/mkcallback.rb ./dlconfig.rb
@echo "Generating callback.func"
- @$(RUBY) $(srcdir)/mkcallback.rb > $@
+ @$(RUBY) $(srcdir)/mkcallback.rb | tee $@
cbtable.func: $(srcdir)/mkcbtable.rb ./dlconfig.rb
@echo "Generating cbtable.func"
- @$(RUBY) $(srcdir)/mkcbtable.rb > $@
+ @$(RUBY) $(srcdir)/mkcbtable.rb | tee $@
debug:
$(MAKE) CPPFLAGS="$(CPPFLAGS) -DDEBUG"
--
1.7.6.1
END_PATCH
)
}
You need to stub it again before the definition installs rubygems
(else it will try to patch rubygems
too):
before_install_package() {
local stub=1
}
REE's tcmalloc
will fail to build too, so the patch itself is slightly longer:
before_install_package() {
(
cd source
patch -p1 <<-"END_PATCH"
From a9936cf3621b2e34ea44abaabd9a4a3dbef37433 Mon Sep 17 00:00:00 2001
From: Reza Jelveh
Date: Thu, 15 Sep 2011 18:51:39 +0200
Subject: [PATCH] archlinux patch
---
distro/google-perftools-1.7/src/tcmalloc.cc | 9 ++++++++-
ext/dl/depend | 6 +++---
2 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/distro/google-perftools-1.7/src/tcmalloc.cc b/distro/google-perftools-1.7/src/tcmalloc.cc
index 8d94d20..0769425 100644
--- a/distro/google-perftools-1.7/src/tcmalloc.cc
+++ b/distro/google-perftools-1.7/src/tcmalloc.cc
@@ -137,6 +137,13 @@
# define WIN32_DO_PATCHING 1
#endif
+// GLibc 2.14+ requires the hook functions be declared volatile, based on the value of the
+// define __MALLOC_HOOK_VOLATILE. For compatibility with older/non-GLibc implementations,
+// provide an empty definition.
+#if !defined(__MALLOC_HOOK_VOLATILE)
+#define __MALLOC_HOOK_VOLATILE
+#endif
+
using STL_NAMESPACE::max;
using STL_NAMESPACE::numeric_limits;
using STL_NAMESPACE::vector;
@@ -1669,5 +1676,5 @@ static void *MemalignOverride(size_t align, size_t size, const void *caller)
MallocHook::InvokeNewHook(result, size);
return result;
}
-void *(*__memalign_hook)(size_t, size_t, const void *) = MemalignOverride;
+void *(*__MALLOC_HOOK_VOLATILE __memalign_hook)(size_t, size_t, const void *) = MemalignOverride;
#endif // #ifndef TCMALLOC_FOR_DEBUGALLOCATION
diff --git a/ext/dl/depend b/ext/dl/depend
index fba3df7..0830ffa 100644
--- a/ext/dl/depend
+++ b/ext/dl/depend
@@ -32,15 +32,15 @@ handle.o: dl.h
call.func: $(srcdir)/mkcall.rb ./dlconfig.rb
@echo "Generating call.func"
- @$(RUBY) $(srcdir)/mkcall.rb > $@
+ @$(RUBY) $(srcdir)/mkcall.rb | tee $@
callback.func: $(srcdir)/mkcallback.rb ./dlconfig.rb
@echo "Generating callback.func"
- @$(RUBY) $(srcdir)/mkcallback.rb > $@
+ @$(RUBY) $(srcdir)/mkcallback.rb | tee $@
cbtable.func: $(srcdir)/mkcbtable.rb ./dlconfig.rb
@echo "Generating cbtable.func"
- @$(RUBY) $(srcdir)/mkcbtable.rb > $@
+ @$(RUBY) $(srcdir)/mkcbtable.rb | tee $@
debug:
$(MAKE) CPPFLAGS="$(CPPFLAGS) -DDEBUG"
--
1.7.6.1
END_PATCH
)
}
Since REE includes rubygems
, this is the only modification needed.
Ruby 1.8.7-p302 and below, and REE (including the current 2012.02 as of this writing) have a known compiler bug, however will complete the rbenv install process. This bug will cause a segmentation fault whenever a SSL connection is opened, most likely in timeout.rb
.
To fix this, pass in the following compiler flags to the ruby-build process:
$ CFLAGS="-O2 -fno-tree-dce -fno-optimize-sibling-calls" rbenv install 1.8.7-pXXX
Ruby 1.9.3 does not seem to work well on OS X 10.7 and newer, and will cause a segmentation fault whenever an SSL connection is opened. To fix this you need to install a newer version of OpenSSL via either Homebrew or MacPorts.
$ brew install openssl
Once you have OpenSSL you need to know its path. Homebrew will warn you about having multiple copies on OS X being dangerous, and won't symlink it into /usr/local
. But it will tell you a path like /usr/local/Cellar/openssl/1.0.1c
which you need to know when building. If you forget, run brew info openssl
to find out where it is. Then with ruby-build you can set the configure options and build a working version of Ruby.
$ CONFIGURE_OPTS="--with-openssl-dir=/usr/local/Cellar/openssl/1.0.1c" rbenv install 1.9.3-p194
rm -rf .rbenv/versions/1.9.3-p0
CONFIGURE_OPTS="--with-arch=i386" CFLAGS="-arch i386" LDFLAGS="-arch i386" ruby-build options
If you want to install a Ruby interpreter that's available to all users and system scripts (no rbenv), use /usr/local/
as the install path. For example:
sudo ruby-build 1.9.3-p194 /usr/local/
You can set your CFLAGS to accepted safe values to help get a little more speed. I found this especially useful for REE on MacOSX.
CFLAGS='-g -O2'
If you encounter this error while installing ruby and your server is a VPS, the /tmp directory where ruby-build download and compile the packages is probably mounted as noexec. You can check with your hosting provider if wether they provide a way to bypass this protection.
If the answer is no, just set the $TMPDIR environment variable to wherever you have a write + execution rights. For example:
export TMPDIR="$HOME/src"
Please note you'll have to do it every time you'll want to install a new version of ruby unless you write this command in your ~/.bashrc
.
If you've got something like that:
$ rbenv install 1.9.3-p194
Downloading http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz...
Installing yaml-0.1.4...
BUILD FAILED
please, be sure to have "make" installed ($ sudo apt-get install make
). On Ubuntu Server, by default, it doesn't.
(also see https://github.com/sstephenson/ruby-build/issues/119 for background) It seems your ruby installation is missing psych (for YAML output). To eliminate this warning, please install libyaml and reinstall your ruby.
- Make sure you have libyaml installed (on Gentoo "emerge libyaml")
- the yaml that gets built by ruby-build seems to miss the libyaml libraries. Manually installing yaml and ruby can solve this (there may be simpler solutions)
cd /tmp
wget http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz
tar xzf yaml-0.1.4.tar.gz
cd yaml-0.1.4
./configure --prefix=/usr/local
make && make install
cd /tmp
wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p194.tar.gz
tar xzf ruby-1.9.3-p194.tar.gz
cd ruby-1.9.3-p194
./configure --prefix=/path/to/rbenv/versions/1.9.3-p194 --enable-shared --disable-install-doc --with-opt-dir=/usr/local/lib
make && make install
rbenv global 1.9.3-p194
This will put the ruby install where rbenv can find it.