Site icon TestingDocs.com

Run Mojo Source File

Overview

Let’s learn the steps to run a Mojo source file. We can use the mojo command to execute the Mojo source code. A Mojo source file contains the Mojo code with the extension *.mojo. Alternatively, we can use the flame emoji as the Mojo file extension. (🔥)

For example:

Install either MAX SDK or Mojo SDK to run the Mojo code. The steps to install the tools are as follows:

Run Mojo Source File

This tutorial will create a mojo program that prints the classic “Hello, World!” message to the console.

Create the Mojo file

$ touch hello.mojo

In Linux, the touch command is used to create empty files or update the timestamps of existing files. Its primary purpose is to create files or change a file’s access and modification times.

Edit the Mojo file

Let’s edit the source file with a simple text editor like gedit to keep it simple.

$ gedit hello.mojo

Edit the file and add the following code. You can ignore the comments that start with
#.

# Sample Mojo Program to print Hello World message
# Mojo Tutorials – www.TestingDocs.com

fn main():
print(“Hello, world!”)

Save the file ( Hit Ctrl + S) and return to your terminal.

 

Run the Mojo code

Type the following command to run the code in the hello.mojo file.

$ mojo hello.mojo

 

This should print the message on the screen.

That’s it. We have successfully executed Mojo code using the mojo CLI command line tool.

More information at Modular official website:

https://www.modular.com/

Exit mobile version