Julia Get Started
You can follow this whole course in the browser, but sooner or later you'll want Julia on your own computer. This lesson shows how to install it, how to use the interactive REPL, and how to run a script.
Installing Julia
The recommended installer is juliaup, a small tool that downloads Julia and keeps it up to date (similar to rustup for Rust).
# Windows (PowerShell or the Microsoft Store)
winget install --name Julia --id 9NJNWW8PVKMN -e -s msstore
# macOS and Linux
curl -fsSL https://install.julialang.org | shAfter installing, open a new terminal and check the version:
$ julia --version
julia version 1.11.2With juliaup you can install several versions side by side:
juliaup add 1.10 # install the long-term-support release
juliaup default 1.11 # choose the version that `julia` starts
juliaup update # update everythingThe REPL
Typing julia with no arguments starts the REPL (Read-Eval-Print Loop). You type an expression, press Enter, and Julia prints its value:
julia> 1 + 2
3
julia> name = "Ada"
"Ada"
julia> uppercase(name)
"ADA"
julia> ans
"ADA"ans always holds the last result. The REPL has several modes, selected by the first key you press on an empty line:
| Key | Mode | Prompt | Used for |
|---|---|---|---|
| (none) | Julian | julia> |
Running Julia code |
? |
Help | help?> |
Reading documentation, e.g. ?println |
] |
Pkg | pkg> |
Installing and managing packages |
; |
Shell | shell> |
Running shell commands like ls |
Press Backspace on an empty line to return to Julian mode, and Ctrl+D (or type exit()) to quit. Tab completion works for names and even Unicode symbols: type \alpha and press Tab to get α.
Running a script
Julia source files use the .jl extension. Save this as hello.jl:
greeting = "Hello"
for name in ["world", "Julia"]
println(greeting, ", ", name, "!")
endHello, world!
Hello, Julia!
and run it from a terminal:
$ julia hello.jl
Hello, world!
Hello, Julia!A script can read its command-line arguments from the global ARGS vector of strings. In the playground there are no arguments, so ARGS is empty:
println("Number of arguments: ", length(ARGS))
println("Arguments: ", ARGS)Number of arguments: 0
Arguments: String[]
You can also load a file into a running REPL with include("hello.jl"), which runs it as if you had typed its contents.
Editors
The most popular setup is Visual Studio Code with the official Julia extension. It gives you syntax highlighting, an integrated REPL, a plot pane, a debugger and inline results. Pluto.jl and Jupyter (via IJulia) are notebook environments popular for teaching and data analysis.
A first program with a function
function greet(name)
return "Welcome to Julia, $(name)!"
end
println(greet("learner"))
println(typeof(greet("x")))Welcome to Julia, learner!
String
Tip: In the REPL, a trailing semicolon hides the result:
x = rand(1000);stores the value without flooding your screen.
Test yourself
Which key switches the Julia REPL into package mode?
- ?
- ;
- ]
- #
What file extension do Julia source files use?
- .julia
- .jul
- .jl
- .ju
Where does a Julia script find its command-line arguments?
- argv
- ARGS
- sys.argv
- args()