Executando com mojo run
Execute um programa pela linha de comando.
Executando com mojo run é uma aula grátis de Mojo Academy no CoddyKit. Esta é a aula 3 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Mojo Academy, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Mojo Academy inclui 4 aulas no total.
Partes desta aula ainda não foram traduzidas e aparecem em inglês.
From File to Running Program
You have a saved hello.mojo file. To see it work, you launch it from your terminal with the mojo command. 🖥️
The mojo run Command
The simplest way to execute a file is mojo run followed by the file name. Mojo compiles and runs it in one step.
mojo run hello.mojoRun from the Right Folder
Open your terminal in the folder that holds the file, or give the full path. Otherwise Mojo cannot find hello.mojo to run.
cd my_project
mojo run hello.mojoSee Your Output
After you press enter, Mojo prints the program's output right in the terminal. Your greeting appears on the next line.
Hello, world!The Shorter Form
You can often drop the word run and just pass the file: mojo hello.mojo does the same thing as mojo run.
mojo hello.mojoEdit, Save, Run Again
Change the code, save, and run the command again to see new output. This quick loop is how you learn fast in Mojo.
Reading an Error Message
If you have a typo, Mojo stops and prints an error with the line number. Read it, fix that line, and run once more.
Run Just Checks for main
mojo run expects your file to have a main function. Without one, it has nothing to start, and you get a clear error.
Building an Executable
For a faster standalone program, mojo build creates an executable file you can run directly, without compiling each time.
mojo build hello.mojorun vs build
Use run while learning and iterating, since it is one quick step. Reach for build when you want a finished binary to ship or reuse.
Your Workflow Is Set
Write code, save the file, type mojo run, read the output. That short cycle is the core habit of every Mojo session.
Quick Check
You want to compile and execute hello.mojo in a single terminal step. Which command does that?
Recap
Use mojo run from the file's folder to compile and execute in one step, read the output, then edit and run again. 🎯
Perguntas Frequentes
A aula “Executando com mojo run” é grátis?
Sim — o texto completo de “Executando com mojo run” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Mojo Academy, atualize para CoddyKit PRO. O curso de Mojo Academy inclui 4 aulas no total.
O que vou aprender em “Executando com mojo run”?
Execute um programa pela linha de comando. Você pratica Mojo Academy com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.
Preciso ter experiência prévia para começar Mojo Academy?
Nenhuma experiência prévia é necessária. Mojo Academy no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 3 de 4.
Quanto tempo leva a aula “Executando com mojo run”?
A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.
Posso escrever e executar código nesta aula de Mojo Academy?
Sim. Cada aula de Mojo Academy inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.
Todas as aulas deste curso
- Seu primeiro arquivo .mojo
- O ponto de entrada main
- Executando com mojo run
- Explorando no REPL do Mojo