Blogging with Jekyll on an M1 Mac

Blogging with Jekyll on an M1 Mac

Live shot of me building my website

Setting up Ruby and Jekyll on M1 Mac: Common Errors and Solutions

A Dispatch from my recent adventures in getting Jekyll to work on Apple silicon. Jekyll is a nice little tool for quickly building and publishing static sites with good balance of control and simplicity.

As GPT-4 says:

  • There’s no database or backend, reducing potential security issues.
  • Allows you to edit pages directly as markdown tiles. View changes in realtime on your local server.
  • It integrates perfectly with GitHub Pages for free hosting.
  • It’s also more flexible for developers comfortable with HTML, CSS, and Markdown, as it allows direct code manipulation.
  • It’s not as feature-rich as WordPress, but this can be a plus for users who prefer a minimalist, bloat-free platform.
  • It’s less time-consuming and error-prone than building a site from scratch, especially for those unfamiliar with web development.
  • Lastly, Jekyll uses a version-controlled system, allowing easy tracking and rollbacks.

Unfortunately, as with what normally happens when installing software on apple silicon, I got a number of cryptic clang, cmake errors while trying to use ruby on my new machine. (Feel free to peruse the error section below). I fixed this by sp? nuking my brew install and being a bit more regimented about how I interact with brew and global language installations with the new architecture. Long story below.

macOS Requirements

This blog specifically addresses the use case of:

  • Apple Silicon.
  • macOS Ventura (11)
  • Command Line Tools (CLT) for Xcode (I have beta installed) for visionOS purposes
  • zsh standard shell

macOS Requirements

If you want to run jekyll on M1 mac, you basically want to:

  • Install homebrew
  • Install the latest version of homebrew
  • run:
      sudo rm -rf /opt/homebrew
    

Unfortunately! It wasn’t so simple

Common Errors and Solutions

I got a lot of weird errors.

  1. Like this:
    ripper.c:10310:9: warning: variable 'yynerrs' set but not used [-Wunused-but-set-variable]
     int yynerrs = 0;
         ^
    compiling sockssocket.c
    compiling udpsocket.c
    compiling unixsocket.c
    compiling unixserver.c
    linking shared-object strscan.bundle
    linking shared-object nkf.bundle
    compiling option.c
    linking shared-object stringio.bundle
    compiling ancdata.c
    compiling raddrinfo.c
    compiling ifaddr.c
    linking shared-object socket.bundle
    1 warning generated.
    linking shared-object ripper.bundle
    make: *** [build-ext] Error 2
    
  2. And this:
User
Installing openssl-3.1.1...
Installed openssl-3.1.1 to /Users/ryanpasecky/.rbenv/versions/3.2.2

Downloading ruby-3.2.2.tar.gz...
-> https://cache.ruby-lang.org/pub/ruby/3.2/ruby-3.2.2.tar.gz
Installing ruby-3.2.2...
    (key) = EVP_PKEY_get0_EC_KEY(_pkey); \
          ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
compiling ossl_ssl_session.c
compiling ossl_ts.c

etc. etc.

After doing some digging, it looks like this might be due to a deteriorated or misconfigured homebrew install

Note: Homebrew Install Fails: If the Homebrew installation fails on an M1 Mac, make sure you have opened Terminal with Rosetta compatibility enabled. Use the arch -x86_64 prefix to force Rosetta when installing Homebrew.

Uninstalling Homebrew

There is an official uninstall script, which also caused its own set of issues. (make sure you don’t have an x86 and arm version installed.) alternatively removing the homebrew command below removed the old installation and kept installed items intact.

sudo rm -rf /opt/homebrew

Installing Homebrew for M1

Homebrew just made it easier, by providing a .pkg installer that handles the platform architecture nuances. Follow the latest instructions here for the .pkg install on macOS.

Setting up Ruby

Once you have a stable homebrew installation, we can proceed with setting up Ruby.

Installing rbenv

I followed the recommendation for using rbenv for managing multiple Ruby versions:

brew install rbenv

Install Ruby

To install Ruby, you can use rbenv and specify the desired version (e.g., 3.2.2):

Use install -l to see latest stable versions:

rbenv install -l

I picked the newest as recommended by jekyll

rbenv install 3.2.2

If you encounter any issues during the Ruby installation, ensure that you have the required dependencies installed, such as openssl, libyaml, and others:

brew install openssl libyaml ...

Activate Ruby Version

After installing Ruby, activate it using rbenv global or rbenv local:

rbenv global 3.2.2

Setting up Jekyll

With Ruby successfully installed, you can now proceed with setting up Jekyll.

Install Bundler

Bundler is a Ruby gem used to manage project dependencies. Install it using gem:

gem install jekyll

You can then run your project with from inside the base directory of your project.

jekyll serve 

Example jeykll websites here

Conclusion

Sweet, now you hopefully have jekyll working on your computer Jekyll is a pretty useful tool for having a low effort way to host your own blog with fairly advanced con Setting up Ruby and Jekyll on an M1 Mac might encounter some challenges due to the new architecture. By uninstalling Homebrew, installing it with Rosetta compatibility, and using rbenv, you can avoid many common errors and ensure a smooth setup. Happy coding and Jekyll blogging on your M1 Mac!

Written on July 28, 2023