8

I am on ubuntu 12.04.5 LTS and tried installing ruby with jemalloc. The jemalloc got installed successfully(https://blog.scalingo.com/2017/05/02/improve-ruby-application-memory-jemalloc.html) but while installing the ruby 2.3.4, it gave this following error.

>rvm install 2.3.4 -C --with-jemalloc

Warning, new version of rvm available '1.29.1', you are using older version '1.27.0'.
You can disable this warning with:    echo rvm_autoupdate_flag=0 >> ~/.rvmrc
You can enable  auto-update  with:    echo rvm_autoupdate_flag=2 >> ~/.rvmrc
ruby-2.3.4 - #removing src/ruby-2.3.4..
Checking requirements for ubuntu.
Requirements installation successful.
Installing Ruby from source to: /home/deploy/.rvm/rubies/ruby-2.3.4, this may take a while depending on your cpu(s)...
ruby-2.3.4 - #downloading ruby-2.3.4, this may take a while depending on your connection...
ruby-2.3.4 - #extracting ruby-2.3.4 to /home/deploy/.rvm/src/ruby-2.3.4....
ruby-2.3.4 - #configuring...........................................................
ruby-2.3.4 - #post-configuration..
ruby-2.3.4 - #compiling.....
Error running '__rvm_make -j2',
showing last 15 lines of /home/deploy/.rvm/log/1494486344_ruby-2.3.4/make.log
compiling enumerator.c
compiling error.c
compiling eval.c
eval.c: In function 'rb_raise_jump':
eval.c:763:8: warning: unused variable 'mid' [-Wunused-variable]
compiling load.c
compiling proc.c
compiling file.c
compiling gc.c
In file included from gc.c:50:0:
/usr/include/malloc.h:152:15: error: conflicting types for 'malloc_usable_size'
/usr/include/jemalloc/jemalloc.h:45:8: note: previous declaration of 'malloc_usable_size' was here
make: *** [gc.o] Error 1
make: *** Waiting for unfinished jobs....
++ return 2
There has been an error while running make. Halting the installation.

Has anyone encountered it before or may have the experience with it, please help.

Bachan Smruty
  • 5,686
  • 1
  • 18
  • 23

3 Answers3

8

On [xK]ubuntu 18.10

I did

sudo apt install libjemalloc-dev
rvm install 2.5.2 -C --with-jemalloc
rvm use 2.5.2
ruby -r rbconfig -e "puts RbConfig::CONFIG['LIBS']"
Mathieu J.
  • 1,932
  • 19
  • 29
  • 1
    Apparently the last command does not check presence of jemalloc anymore. Suggested check is now `MALLOC_CONF=stats_print:true ruby -e "exit"` [source](https://github.com/gaffneyc/heroku-buildpack-jemalloc/issues/5#issuecomment-499932026) – Axe Jul 29 '21 at 08:23
2

I use Ubuntu 18.04. Change the command like this

RUBY_EXTRA_CONFIGURE_OPTIONS="--with-jemalloc" rvm install 2.3.4 --disable-binary

To check the jemalloc is installed, run the following command:

ruby -r rbconfig -e "puts RbConfig::CONFIG['LIBS']"

if the ruby is unrecognized after rvm is installed.

source ~/.rvm/scripts/rvm

When the jemalloc is called. You can see the response.

-lpthread -ljemalloc -ldl -lobjc

You can see the full documentation here

akbarbin
  • 4,985
  • 1
  • 28
  • 31
  • 2
    I tried RUBY_EXTRA_CONFIGURE_OPTIONS="--with-jemalloc" several times without success, turns out the proposed version in the question worked just fine. I did it on Kubuntu 18.10 installing ruby 2.5.2 make sure you have `sudo apt install libjemalloc-dev` done first – Mathieu J. Mar 09 '19 at 08:07
2

I ran across a variant of this issue when trying to get rails to use jemalloc. In my case I had (purposefully) installed system-wide rubies via rvm but forgotten to use rvmsudo like so:

$ sudo apt update; sudo apt install libjemalloc-dev -y
$ rvmsudo rvm reinstall 2.4.1 -C --with-jemalloc

If you're getting permissions warnings when trying to get jemalloc to work in an analogous scenario, give ^^^ a shot...

Jacob
  • 61
  • 4