Mojo Installation

Developer
Super fast Python! Speed up your AI workflow. Install Modular’s Mojo on macOS.
Author

Craig A Miller

Published

July 11, 2024

Modular’s macOS installation directions have several errors.1 The following are the correct steps as of 07/10/2024.

Introduction

Made by the original architect of Swift, Chris Lattner, Mojo is Modular’s new high performance programming language for AI and Data Science. Blazingly fast. As a superset of Python it’s easy to learn. Before you can do that, you’ll need to install it.

In order to use Mojo from the command line and from VSCode there are several steps necessary that are not clearly documented on the modular website. This article describes the specific steps necessary to install Mojo on macOS and configure it for use with VSCode.

Note

This article is current as of 5/1/2024 Please let me know if Modular corrects their installation instructions and I’ll take the article down.

Requirements

  • Apple Silicon
  • macOS Monterey (12 or later)
  • Python 3.8-3.12
  • Command Line Tools for XCode
  • Uses Homebrew - I already had it installed.
  • Uses curl - I already had it installed via Homebrew

Installation

  1. As a normal user - Install modular
$ curl -s https://get.modular.com | sh -
  1. Setup a modular account https://developer.modular.com

  2. As a normal user - Authorize the modular client

$ modular auth

This will output a URL, where you can confirm the client in your developer account. For example:

To complete auth, open this web page:
https://developer.modular.com/device?userCode=RCDJ-ZCVV
  1. As sudo/root - Install the Mojo SDK

If you’ve attempted an install before, first clean things up

$ modular clean

Then install mojo as sudo/root

\# sudo modular install mojo
  1. Update your zshrc or bashrc Be sure to follow the instructions to update your zshrc or .bashrc as described in the output of the previous command.

  2. Test

mojo --version

Install VSCode Mojo Extension

  1. Restart VSCode The VSCode Mojo extension needs the MODULAR_HOME environment variable to work properly. You can either pick this up from your global environment or you can set it specifically in the VSCode Mojo extension settings. Since we just updated our MODULAR_HOME environment variable, let’s keep it simple and use that.

Quit and Restart VSCode

  1. Find the official Mojo extension for VSCode and install

VSCode Mojo Test

  1. Create a file ‘hello.mojo’
  2. Add
  fn main():
  print("Hello, world!")
  1. Run it, and insure you see Hello World in the console output.

Congratulations. You now have mojo support in VSCode

Footnotes

  1. https://docs.modular.com/mojo/manual/get-started/#system-requirements↩︎