Introduction to the Julia programming language
2 Installing and Running Julia¶
N.B. If you installed a tarball, you might need to add Julia's bin
directory to your PATH
.
Running Julia¶
$ julia
_
_ _ _(_)_ | Documentation: https://docs.julialang.org
(_) | (_) (_) |
_ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 1.10.2 (2024-03-01)
_/ |\__'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |
julia>
You will be to now type Julia commands in a standard REPL environment: read, evaluate, print, loop.
This is an almost exact Julia analogue of Python's ipython
.
julia> println("hello, world!")
hello, world!
julia> (2+3)^2
25
julia>
Notebooks¶
Julia will run in a Jupyter notebook environment, e.g., using Jupyter Lab or in VS Code.
Julia Scripts¶
Finally, let's just observe that Julia scripts work just as one would expect:
#! /usr/bin/env julia
function main()
println("hello, world! let's calculate a sum of squares")
total = 0
for i in 1:10
total += i^2
end
println("The answer is $(total)")
end
main()
So let's execute that:
$ julia julia-script.jl
hello, world! let's calculate a sum of squares
The answer is 385
Bonus Installation Method: juliaup
¶
Another way to manage a Julia install is with Juliaup - a Julia toolkit installation manager inspired by the excellent Rustup for the Rust programming language.
Once installed, you can simply type in a terminal:
juliaup list
to show all the versions of Julia available.
We will work with the newest version on all platforms, 1.9.3 so simply type
juliaup install 1.9.3
to set that up.
The big bonus with juliaup
is that you can easily have multiple Julia releases installed at once, and Juliaup will let you configure which is your default at any point in time.