So, THAT 35000-times-faster-than-python language, mojo, released its SDK today. This means you can install Mojo in your own environment and run mojo programs.
And here in this post, I will show you how to do it on Ubuntu.
System Requirements
- Ubuntu 20.04 and later
- x86-64 CPU and minimum 4 GB RAM
- Python 3.8 - 3.10
- g++ or clang++ compiler
My environment
- Kubuntu 22.04.3
- AMD CPU with 16GB RAM
- Python 3.10.12
- g++ 11.4.0
Install steps
1. Install Modular CLI
# switch to root first
sudo -u root -i
# then run the following command
apt-get install -y apt-transport-https &&
keyring_location=/usr/share/keyrings/modular-installer-archive-keyring.gpg &&
curl -1sLf 'https://dl.modular.com/bBNWiLZX5igwHXeu/installer/gpg.0E4925737A3895AD.key' | gpg --dearmor >> ${keyring_location} &&
curl -1sLf 'https://dl.modular.com/bBNWiLZX5igwHXeu/installer/config.deb.txt?distro=debian&codename=wheezy' > /etc/apt/sources.list.d/modular-installer.list &&
apt-get update &&
apt-get install -y modular
# switch back to normal user
exit
2. Verify modular
is installed
which modular
/usr/bin/modular
3. Install Mojo SDK
modular auth <YOUR AUTH KEY> && modular install mojo
# Found release for https://packages.modular.com/mojo @ 0.2.1, installing to /home/******/.modular/pkg/packages.modular.com_mojo
# Downloads complete, setting configs...
# Configs complete, running post-install hooks...
..................<OMITTED>
Successfully installed ansiwrap-0.8.4 attrs-23.1.0 certifi-2023.7.22 charset-normalizer-3.2.0 entrypoints-0.4 fastjsonschema-2.18.0 find_libpython-0.3.0 idna-3.4 jsonschema-4.19.0 jsonschema-specifications-2023.7.1 jupyter-core-5.3.1 jupyter_client-8.3.1 nbclient-0.8.0 nbformat-5.9.2 papermill-2.4.0 platformdirs-3.10.0 python-dateutil-2.8.2 pyzmq-25.1.1 referencing-0.30.2 requests-2.31.0 rpds-py-0.10.2 tenacity-8.2.3 textwrap3-0.9.2 tornado-6.3.3 tqdm-4.66.1 traitlets-5.9.0 urllib3-2.0.4
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
Testing `MODULAR_HOME=/home/******/.modular`
* `/home/******/.modular/pkg/packages.modular.com_mojo/bin/mojo`...
TEST: `mojo --help`... OK
TEST: `mojo run --help`... OK
TEST: `mojo build test_mandelbrot.mojo`... OK
TEST: `mojo build test_python.mojo`... OK
TEST: `mojo demangle`... OK
TEST: `mojo format`... OK
TEST: `mojo package`... OK
TEST: `mojo test_mandelbrot.mojo`... OK
TEST: `mojo test_python.mojo`... OK
TEST: `mojo repl`... OK
ðĨ Mojo installed! ðĨ
Now run the following commands if you are using bash:
echo 'export MODULAR_HOME="/home/******/.modular"' >> ~/.bashrc
echo 'export PATH="/home/******/.modular/pkg/packages.modular.com_mojo/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
If you are using ZSH, run the following commands:
echo 'export MODULAR_HOME="/home/******/.modular"' >> ~/.zshrc
echo 'export PATH="/home/******/.modular/pkg/packages.modular.com_mojo/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
Then enter 'mojo' to start the Mojo REPL.
For tool help, enter 'mojo --help'.
For more docs, see https://docs.modular.com/mojo.
4. Add mojo to PATH
# You must replace two <USERNAME> with your own username
echo 'export MODULAR_HOME="/home/<USERNAME>/.modular"' >> ~/.bashrc
echo 'export PATH="/home/<USERNAME>/.modular/pkg/packages.modular.com_mojo/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
Now verify mojo
command is accesible:
which mojo
/home/******/.modular/pkg/packages.modular.com_mojo/bin/mojo
5. Mojo REPL
mojo
Welcome to Mojo! ðĨ Expressions are delimited by a blank line. Type
:mojo help
for further assistance.
Bonus Round: directory structure
tree $MODULAR_HOME
/home/******/.modular
âââ crashdb
â âââ attachments
â âââ completed
â âââ new
â âââ pending
â âââ settings.dat
âââ modular.cfg
âââ pkg
âââ packages.modular.com_mojo
âââ bin
â âââ lldb
â âââ lldb-argdumper
â âââ lldb-server
â âââ lldb-vscode
â âââ modular-crashpad-handler
â âââ mojo
â âââ mojo-lsp-server
âââ installed.json
âââ jupyter
â âââ kernel
â â âââ logo-64x64.png
â â âââ logo.svg
â â âââ mojokernel.py
â âââ manage_kernel.py
âââ lib
â âââ libKGENCompilerRTShared.so -> /home/******/.modular/pkg/packages.modular.com_mojo/lib/libKGENCompilerRTShared.so.18git
â âââ libKGENCompilerRTShared.so.18git
â âââ libKGENCompilerRT-static.a
â âââ libLLCLRuntimeGlobals.so -> /home/******/.modular/pkg/packages.modular.com_mojo/lib/libLLCLRuntimeGlobals.so.18git
â âââ libLLCLRuntimeGlobals.so.18git
â âââ liblldb.so -> /home/******/.modular/pkg/packages.modular.com_mojo/lib/liblldb.so.18.0.0git
â âââ liblldb.so.18.0.0git
â âââ liblldb.so.18git -> /home/******/.modular/pkg/packages.modular.com_mojo/lib/liblldb.so.18.0.0git
â âââ libMojoJupyter.so -> /home/******/.modular/pkg/packages.modular.com_mojo/lib/libMojoJupyter.so.18git
â âââ libMojoJupyter.so.18git
â âââ libMojoLLDB.so -> /home/******/.modular/pkg/packages.modular.com_mojo/lib/libMojoLLDB.so.18git
â âââ libMojoLLDB.so.18git
â âââ libMSupportGlobals.so -> /home/******/.modular/pkg/packages.modular.com_mojo/lib/libMSupportGlobals.so.18git
â âââ libMSupportGlobals.so.18git
â âââ liborc_rt.a
â âââ lldb-visualizers
â â âââ lldbDataFormatters.py
â â âââ mlirDataFormatters.py
â âââ mblack
â â âââ base_library.zip
â â âââ importlib_metadata-6.8.0.dist-info
â â â âââ INSTALLER
â â â âââ LICENSE
â â â âââ METADATA
â â â âââ RECORD
â â â âââ top_level.txt
â â â âââ WHEEL
â â âââ libbz2.so.1.0
â â âââ libcrypto.so.1.1
â â âââ lib-dynload
â â â âââ _asyncio.cpython-38-x86_64-linux-gnu.so
â â â âââ _bz2.cpython-38-x86_64-linux-gnu.so
â â â âââ _codecs_cn.cpython-38-x86_64-linux-gnu.so
â â â âââ _codecs_hk.cpython-38-x86_64-linux-gnu.so
â â â âââ _codecs_iso2022.cpython-38-x86_64-linux-gnu.so
â â â âââ _codecs_jp.cpython-38-x86_64-linux-gnu.so
â â â âââ _codecs_kr.cpython-38-x86_64-linux-gnu.so
â â â âââ _codecs_tw.cpython-38-x86_64-linux-gnu.so
â â â âââ _contextvars.cpython-38-x86_64-linux-gnu.so
â â â âââ _ctypes.cpython-38-x86_64-linux-gnu.so
â â â âââ _decimal.cpython-38-x86_64-linux-gnu.so
â â â âââ _hashlib.cpython-38-x86_64-linux-gnu.so
â â â âââ _json.cpython-38-x86_64-linux-gnu.so
â â â âââ _lzma.cpython-38-x86_64-linux-gnu.so
â â â âââ mmap.cpython-38-x86_64-linux-gnu.so
â â â âââ _multibytecodec.cpython-38-x86_64-linux-gnu.so
â â â âââ _multiprocessing.cpython-38-x86_64-linux-gnu.so
â â â âââ _opcode.cpython-38-x86_64-linux-gnu.so
â â â âââ _posixshmem.cpython-38-x86_64-linux-gnu.so
â â â âââ _queue.cpython-38-x86_64-linux-gnu.so
â â â âââ resource.cpython-38-x86_64-linux-gnu.so
â â â âââ _ssl.cpython-38-x86_64-linux-gnu.so
â â â âââ termios.cpython-38-x86_64-linux-gnu.so
â â â âââ _uuid.cpython-38-x86_64-linux-gnu.so
â â âââ libexpat.so.1
â â âââ libffi.so.7
â â âââ liblzma.so.5
â â âââ libmpdec.so.2
â â âââ libpython3.8.so.1.0
â â âââ libssl.so.1.1
â â âââ libuuid.so.1
â â âââ libz.so.1
â â âââ mblack
â â âââ mblib2to3
â â âââ Grammar.txt
â â âââ __init__.py
â â âââ LICENSE
â â âââ PatternGrammar.txt
â â âââ pgen2
â â â âââ conv.py
â â â âââ driver.py
â â â âââ grammar.py
â â â âââ __init__.py
â â â âââ literals.py
â â â âââ parse.py
â â â âââ pgen.py
â â â âââ tokenize.py
â â â âââ token.py
â â âââ pygram.py
â â âââ pytree.py
â â âââ README
â âââ mojo
â â âââ algorithm.mojopkg
â â âââ autotune.mojopkg
â â âââ base64.mojopkg
â â âââ benchmark.mojopkg
â â âââ builtin.mojopkg
â â âââ complex.mojopkg
â â âââ math.mojopkg
â â âââ memory.mojopkg
â â âââ os.mojopkg
â â âââ python.mojopkg
â â âââ random.mojopkg
â â âââ runtime.mojopkg
â â âââ sys.mojopkg
â â âââ tensor.mojopkg
â â âââ testing.mojopkg
â â âââ time.mojopkg
â â âââ utils.mojopkg
â âââ mojo-repl-entry-point
âââ licenses
â âââ LICENSE
â âââ Third-Party-Notices
âââ modular.cfg
âââ root.json
âââ scripts
â âââ post-install
â âââ install-dependencies.sh
â âââ pick_python.py
â âââ requirements.txt
â âââ self-test.py
âââ share
â âââ man
â âââ man1
â âââ mojo.1
â âââ mojo-build.1
â âââ mojo-demangle.1
â âââ mojo-doc.1
â âââ mojo-format.1
â âââ mojo-package.1
â âââ mojo-repl.1
â âââ mojo-run.1
âââ snapshot.json
âââ targets.json
âââ test
â âââ test_format.mojo
â âââ test_jupyter.ipynb
â âââ test_mandelbrot.mojo
â âââ test_package
â â âââ __init__.mojo
â âââ test_package_user.mojo
â âââ test_python.mojo
âââ timestamp.json
âââ VERSION
26 directories, 133 files