Search code examples
rubygemsjekyllgithub-pagesrbenv

How do I force jekyll to use a specific version when multiple versions are installed?


I'm in the process of setting up my own Github Pages. I wanted to test the site on local machine before pushing to the remote repo. I followed the instructions from https://help.github.com/en/github/working-with-github-pages/creating-a-github-pages-site-with-jekyll.

As per instructions, I tried jekyll 3.8.5 new command, since jekyll-3.8.5 is the version github pages uses (https://pages.github.com/versions/). However, jekyll is not able to find version 3.8.5 in my system.

This is on macOS Catalina, with rbenv installed to manage ruby versions. I have tried manually invoking the jekyll version 3.8.5. That totally works.

Here are some snippets from attempt. gem list do show 3.8.5 as available version. But jekyll 3.8.5 new command bombed out.

$ gem list jekyll

*** LOCAL GEMS ***

jekyll (4.0.0, 3.8.6, 3.8.5)

$ which jekyll
/Users/deep/.gem/ruby/2.6.0/bin/jekyll

$ jekyll 3.8.5 new mygh-site
fatal: 'jekyll 3.8.5' could not be found. You may need to install the jekyll-3.8.5 gem or a related gem to be able to use this subcommand.

I was able to explicitly invoke jekyll-3.8.5 from the path where it is installed.

$ /Users/deep/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/jekyll-3.8.5/exe/jekyll new mygh-site

How do I make use of version 3.8.5 when multiple versions of jekyll are present? Appreciate any help to get past this failure.


Solution

  • Your which jekyll command suggests you are not using the versions installed through rbenv (likely the system install instead), for me it's this:

    $ which jekyll
    ~/.rbenv/shims/jekyll
    

    I'd double check your rbenv install instructions (looks installed but not integrated), you might be missing the rbenv init command (https://github.com/rbenv/rbenv#how-rbenv-hooks-into-your-shell)


    Once you've got that sorted, the convention has underscores either side of the version:

    $ jekyll _3.8.5_ -v
    jekyll 3.8.5
    
    $ jekyll _2.4.0_ -v
    jekyll 2.4.0
    

    Since you are using rbenv, make sure you run rbenv rehash after installing a gem so it'll be accessible.