The Julia REPL (Read-Eval-Print Loop) serves as an excellent tool for experimenting with code snippets and obtaining immediate feedback. However, for larger programs or reusable utilities, saving your work becomes essential. Julia scripts fulfill this purpose. A Julia script is a plain text file containing Julia code, typically saved with a .jl extension.
To write a Julia script, you'll need a text editor. In the previous section, "Choosing Your Julia Development Environment," we discussed various options. If you've set up an Integrated Development Environment (IDE) like Visual Studio Code with the Julia extension, or an editor like Atom with Juno, you can use that. For now, even a basic text editor like Notepad (on Windows), TextEdit (on macOS, ensuring it's in plain text mode), or Gedit (on Linux) will suffice.
Open your chosen text editor. This will give you a blank canvas to write your code.
Type the following line of code:
println("Hello, Julia!")
This line uses the println() function. The println (short for "print line") function is a fundamental Julia command used to display text or values to the console. Whatever you put inside the parentheses and quotes will be printed, followed by a newline character, which moves the cursor to the next line in the console.
Save the file.
File > Save As... in your text editor.julia_projects.hello.jl. It's important to use the .jl extension, as this tells the system (and the Julia interpreter) that it's a Julia file.You've now written your first Julia script! It's a simple one, but the process is the same for scripts of any complexity.
With your hello.jl script saved, the next step is to run it. This is typically done using your system's command line interface (CLI), also known as the terminal or command prompt.
Open your terminal or command prompt:
Ctrl+Alt+T or find "Terminal" in your applications menu.Navigate to the directory where you saved your file. The terminal usually opens in your home directory. You'll need to use the cd (change directory) command to move to the folder containing hello.jl.
cd Desktopjulia_projects inside your Documents folder, you might type (adjust paths as needed):
cd Documents/julia_projects (on macOS/Linux)
cd Documents\julia_projects (on Windows)You can use the ls (on macOS/Linux) or dir (on Windows) command to list the files in the current directory to confirm hello.jl is there.
Run the script. Once you are in the correct directory, type the following command and press Enter:
julia hello.jl
This command tells the Julia interpreter (the julia part) to execute the code contained in the hello.jl file.
You should see the following output printed to your terminal:
Hello, Julia!
Congratulations! You've successfully written and executed your first Julia script.
If you are using an IDE like VS Code with the Julia extension, there's often a "Run" button (usually a triangle icon) or a command in the menu (e.g., "Julia: Execute File") that can run the script directly within the IDE, handling the terminal commands for you. This can be more convenient for development.
Let's expand on our first script to see a bit more. Open your hello.jl file (or create a new one, perhaps myscript.jl) and modify it or type the following:
# This is a comment. Julia ignores lines starting with #.
# Storing a message in a variable
message = "Start Julia scripting!"
println(message)
# Performing a simple calculation
base_value = 15
multiplier = 3
result = base_value * multiplier
println("The result of the calculation is: ", result)
println("We multiplied ", base_value, " by ", multiplier, ".")
Save this file and run it from your terminal using julia <your_filename>.jl.
The output will be:
Welcome to Julia scripting!
The result of the calculation is: 45
We multiplied 15 by 3.
In this example:
# are comments. They are for human readers to understand the code; Julia ignores them.message, base_value, multiplier, result) to store data (text and numbers). We'll cover variables in detail in the next chapter.* is the multiplication operator).println can print the content of variables and can also print multiple items if you separate them with commas.The process you've just followed:
This is the fundamental workflow for most programming. As you develop more complex programs, you'll repeat this cycle many times, gradually building and refining your code.
By writing and running these simple scripts, you've taken an important step. You now know how to create standalone Julia programs that can be executed, saved, and shared. In the following sections and chapters, we'll build upon this foundation, exploring Julia's syntax, data types, and features in more detail.
Was this section helpful?
© 2026 ApX Machine LearningEngineered with