How to Install Ruby 3.3 with YJIT Enabled
- Categories:
- tutorial
In this blog post, I will explain how to install Ruby with YJIT enabled and chruby. If you are looking for Ruby installation without YJIT, please visit How To Install Ruby 3.2 with chruby and uninstall Ruby 3.1 from chruby post.
YJIT is a lightweight, minimalistic Ruby JIT built inside CRuby. it is a new just-in-time compiler for Ruby that was introduced in Ruby 3.0.
YJIT promises faster performance for Ruby programs by compiling them at runtime. It lazily compiles code using a Basic Block Versioning (BBV) architecture. The target use case is that of servers running Ruby on Rails.
Requirements
- Ruby dependencies.
- chruby - I assume chruby is already installed, I’ll skip the installation process.
- The Rust compiler rustc and Cargo (if you want to build in dev/debug mode)
- The Rust version must be >= 1.58.0.
Ruby Dependencies
-
Install the prerequisite dependencies for building the CRuby interpreter:
- C compiler
For RubyGems, you will also need:
- OpenSSL 1.1.x or 3.0.x / LibreSSL
- libyaml 0.1.7 or later
- zlib
If you want to build from the git repository, you will also need:
- autoconf - 2.67 or later
- bison - 3.0 or later
- gperf - 3.1 or later
- Usually unneeded; only if you edit some source files using gperf
- ruby - 2.5 or later
- We can upgrade this version to system ruby version of the latest Ubuntu LTS.
-
Install optional, recommended dependencies:
- readline/editline (libedit, to build readline)
- libffi (to build fiddle)
- gmp (if you with to accelerate Bignum operations)
- libexecinfo (FreeBSD)
- rustc - 1.58.0 or later (if you wish to build YJIT)
If you installed the libraries needed for extensions (openssl, readline, libyaml, zlib) into other than the OS default place, typically using Homebrew on macOS, add
--with-EXTLIB-dir
options toCONFIGURE_ARGS
environment variable.export CONFIGURE_ARGS="" for ext in openssl readline libyaml zlib; do CONFIGURE_ARGS="${CONFIGURE_ARGS} --with-$ext-dir=$(brew --prefix $ext)" done
Using Ubuntu, just copy and paste command below to install the required dependencies:
How to Install Rust:
MRI Ruby 3.2 Installation with YJIT Enabled for chruby
You can test that YJIT works correctly by running:
If the installation is successful, upon reloading the shell, running chruby
will display ruby-3.3.1
:
Note that there is also an environment variable RUBY_YJIT_ENABLE
which can be used to enable YJIT. This can be useful for some deployment scripts where specifying an extra command-line option to Ruby is not practical.
You can verify that YJIT is enabled by checking that ruby -v --yjit
includes the string +YJIT
:
- Tags:
- #ruby
Sponsored Links
- Register to Digital Ocean cloud with this link and get $200 credit
- Looking for cheap CDN? Bunny is the answer
- Alternative Cloud besides AWS and Digital Ocean