Mojo Installation
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.
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
- As a normal user - Install modular
$ curl -s https://get.modular.com | sh -
Setup a modular account https://developer.modular.com
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
- 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
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.
Test
mojo --version
Install VSCode Mojo Extension
- 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
- Find the official Mojo extension for VSCode and install
VSCode Mojo Test
- Create a file ‘hello.mojo’
- Add
fn main():
print("Hello, world!")
- Run it, and insure you see Hello World in the console output.
Congratulations. You now have mojo support in VSCode
Footnotes
https://docs.modular.com/mojo/manual/get-started/#system-requirements↩︎