I managed to add jemalloc using the following steps:
Install the Jemalloc library, preferably using your distro's package manager. (apt, pacman, brew, etc.):
# For instance, on Ubuntu:
sudo apt install libjemalloc-dev
Reinstall the currently installed ruby version with a compilation flag to include Jemalloc support:
rvm reinstall 2.6.6 -C --with-jemalloc
Older versions of ruby used the compilation flag syntax -with-jemalloc
(with a single dash) but Ruby 2.6 and up use --with-jemalloc
(with a double dash).
Then check that Jemalloc support has been added properly:
# For ruby >= 2.6:
ruby -r rbconfig -e "puts RbConfig::CONFIG['MAINLIBS']"
# For ruby < 2.6:
ruby -r rbconfig -e "puts RbConfig::CONFIG['LIBS']"
It should output something like:
-lpthread -ljemalloc -lgmp -ldl -lcrypt -lm