Using non-system ruby version on MacOS

Jekyll 4.1.1

ruby -v
ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin19]

rbenv versions

  • system (set by /Users/redwood/.rbenv/version)
    2.7.2
    ===========================

I installed ruby version 2.7.2 using rbenv as per the jekyllrb documentation. However when I run jekyll new new_site, it keeps using the system version of ruby.

How do I make jekyll use the rbenv version of ruby instead?

Have you run rbenv init? I believe that sets up the necessary path changes to access the rbenv version of Ruby.

I have this in my ~/.zshrc

eval "$(rbenv init -)"

Just tried to resource the .zshrc again and then ran ruby -v. Still using the old version.

If that rbenv init call runs correctly, then it should have add the rbenv’s shim directory to the path. You can check the PATH variable and which Ruby is found as follows, and you should see something like this:

$ echo $PATH
/Users/me/.rbenv/shims:...

$ which ruby
/Users/me/.rbenv/shims/ruby

This is what I see:

echo $PATH

/Users/redwood/.gem/ruby/2.7.0/bin:/Users/redwood/.rbenv/shims:/Users/redwood/.gem/ruby/2.7.0/bin:/Users/redwood/.rbenv/shims:

which ruby

/Users/redwood/.rbenv/shims/ruby

/Users/redwood/.rbenv/shims/ruby -v

ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin19]

It is unclear to me why rbenv is linked to the system version of ruby.

Possibly you don’t have 2.7.2 set as your global version? From the above output of rbenv versions, it looks like the global version is set to system, so macOS’s 2.6 is used. Try:

rbenv global 2.7.2

Also, it is odd that you have ~/.gem/... in your path, in front of rbenv’s shims. Also odd that both are on the path twice. Possibly you have a different Ruby setup in your .zshrc which may cause trouble with rbenv.

Thanks for helping me troubleshoot. A few more points:

  1. These are the only two lines in my ~/.zshrc:

    eval "$(rbenv init -)" export PATH="$HOME/.gem/ruby/2.7.0/bin:$PATH"

  2. When I installed 2.7.2, I followed the directions from Jekyllrb.com’s macos page. In their example code based on ruby version 2.7.1p83, they suggest putting in your path, version number 2.7.0. So that’s probably why my version shows up as 2.7.0 even though I have 2.7.2.

  3. Running rbenv global 2.7.2 simply returns the prompt suggesting that I already have 2.7.2.

After running rbenv global 2.7.2, rbenv should have reset your default Ruby to 2.7.2. You can verify with rbenv versions and ruby -v, which should now show:

# Note: the currently set version is marked with a "*"
$ rbenv versions
  system
* 2.7.2 (set by /Users/me/.rbenv/version)

$ ruby -v
ruby 2.7.2 ...