Skip to main content

Hello World (first programs) · Beginner · 15 min

Hello World in Julia: juliaup, the REPL and multiple dispatch

By Padding · Updated 18 Nov 2026
Julia 1.13.4 · julia:1.13

You will install Julia 1.13 with juliaup, use the REPL's help and package modes, run a script that greets you by name, see the first-call compile delay, write a function with two methods and give a project its own package environment.

On this page

Julia was designed for numerical work that has to be both quick to write and fast to run. You write it like a scripting language, with no type declarations and no build step, but it is not interpreted line by line: the first time you call a function, Julia compiles it to native machine code for the exact types you passed in, using the LLVM compiler. That is why a Julia loop can run at speeds close to C, and also why the first call to anything is noticeably slower than the second.

In this tutorial you install Julia 1.13 with juliaup, try the REPL and its modes, save and run a script, and watch that first-call delay happen. Then you go one step further: you write a function with two methods, which is how Julia organises almost all of its code, and you give a project its own package environment.

Julia is used for scientific computing, numerical modelling, optimisation and some machine learning: climate and ocean models, pharmaceutical dosing models, energy grid planning and the JuMP optimisation library are all written in it. Three habits mark it out from Python and R, and you meet each of them below: arrays start at 1, any Unicode letter can be part of a name (so α and σ² are ordinary variable names), and functions are split into methods chosen by the types of all their arguments.

Step 1 · Install Julia with juliaup

juliaup is the official Julia installer. It installs the current release, keeps it up to date and lets you add other versions side by side. Use it rather than your system's package manager, which often ships an old Julia.

  • Ubuntu or macOS: run the installer and accept the default answers:
Bash
curl -fsSL https://install.julialang.org | sh

The installer adds Julia to your PATH, the list of folders your terminal searches for programs, by editing your shell's start-up file. Close the terminal and open a new one so it sees the change.

  • Windows: in PowerShell, install juliaup from the Microsoft Store with winget, then open a new terminal:
Bash
winget install --name Julia --id 9NJNWW8PVKMN -e -s msstore

Now check the version:

Bash
julia --version

Later, juliaup update moves you to the newest patch release, and juliaup status lists the versions you have. The download is large (well over 100 MB), so on prepaid mobile data it is worth running the installer over Wi-Fi.

Check it worked

The terminal prints julia version 1.13.4 (or a later 1.13 patch). command not found means the new PATH has not been picked up: open a new terminal and try again.

Step 2 · Use the REPL and its modes

Start Julia with no file name to open the REPL (read, evaluate, print loop):

Bash
julia

You see the Julia banner and a julia> prompt. Type each line and press Enter:

Text
julia> println("Hello, world")
Hello, world

julia> 1 + 2
3

julia> xs = [10, 20, 30]
3-element Vector{Int64}:
 10
 20
 30

julia> xs[1]
10
  • println prints its argument and then a new line. The REPL shows nothing after it, because println returns nothing.
  • 1 + 2 shows its value, 3. The REPL prints the value of whatever you type, unless you end the line with ;.
  • [10, 20, 30] makes an array, which Julia calls a Vector. Int64 is the type of its elements: 64-bit whole numbers.
  • xs[1] is the first element. Julia counts from 1, like R, MATLAB and Fortran, and unlike Python and C.

Now try a Unicode name. Type \alpha, press Tab, and Julia replaces it with α:

Text
julia> α = 0.5
0.5

julia> 2α
1.0

2α means 2 * α: Julia lets a number sit directly in front of a variable, as in maths notation.

The REPL has other modes, each switched on by typing one character at the start of an empty line:

  • ? switches to help mode. The prompt becomes help?>. Type println and press Enter to read its documentation.
  • ] switches to package mode. The prompt becomes (@v1.13) pkg>, which names the environment packages go into. Type status to list installed packages (none yet).
  • ; switches to shell mode, shell>, for running terminal commands without leaving Julia.

Press Backspace on an empty line to return to julia>. Leave the REPL with exit() or Ctrl+D.

Check it worked

println("Hello, world") prints Hello, world, xs[1] shows 10, and 2α shows 1.0. Typing ? changes the prompt to help?> and ] changes it to (@v1.13) pkg>. After exit() your normal terminal prompt is back.

Step 3 · Save hello.jl and run it

Make a folder for this tutorial and create hello.jl in it. On macOS or Linux you can paste the whole block into the terminal; on Windows, create the file in your editor with the lines between the JULIA markers.

Bash
mkdir -p ~/hello-julia-demo
cd ~/hello-julia-demo
cat > hello.jl <<'JULIA'
# My first Julia script
println("Hello, world")

name = isempty(ARGS) ? "stranger" : ARGS[1]
println("Hello, $name. Your name has $(length(name)) characters.")
JULIA
julia hello.jl
julia hello.jl Amara

Line by line:

  • # My first Julia script is a comment. Julia ignores everything from # to the end of the line.
  • println("Hello, world") prints the text and a new line, as in the REPL. A script does not echo values; only what you print appears.
  • ARGS is an array of the words typed after the file name on the command line. isempty(ARGS) ? "stranger" : ARGS[1] reads as "if ARGS is empty, use "stranger", otherwise use the first word". The first word is ARGS[1], because arrays start at 1.
  • "Hello, $name." is string interpolation: Julia replaces $name with the variable's value. $(length(name)) does the same for a whole expression.
  • length(name) counts characters, not bytes, so a name with accented letters such as Ìfẹ́ is counted by its characters rather than the extra bytes those letters take.
  • julia hello.jl starts Julia, parses the file and runs it from top to bottom. julia hello.jl Amara passes Amara in ARGS.

Check it worked

The first run prints Hello, world and Hello, stranger. Your name has 8 characters. The second prints Hello, world and Hello, Amara. Your name has 5 characters.

Step 4 · Watch the first-call compile delay

Each time Julia meets a function call with a combination of argument types it has not seen, it compiles a native version of that function for those types. The @time macro shows how long a call took and how much of that was compiling. Create timing.jl:

Bash
cat > timing.jl <<'JULIA'
sumsquares(n) = sum(i^2 for i in 1:n)

n = 1_000
@time sumsquares(n)
@time sumsquares(n)
m = Int32(1_000)
@time sumsquares(m)

println(sumsquares(1_000))
JULIA
julia timing.jl

Line by line:

  • sumsquares(n) = sum(i^2 for i in 1:n) defines a function in one line. It adds up 1², 2², and so on up to n². 1:n is the range 1 to n, including both ends.
  • n = 1_000 stores the number 1000 in a variable. The underscore in 1_000 is only there to make it easier to read.
  • @time sumsquares(n) runs the call and prints its timing. The @ marks a macro, code that rewrites other code before it runs. The argument is a variable rather than a literal 1_000 on purpose: with a literal, Julia can compile the call before @time starts its clock, and the compile time would not show.
  • The second @time line makes the same call again.
  • m = Int32(1_000) is the same number stored as a 32-bit integer, a different type from the default Int64, and the third @time calls the function with it.
  • println(sumsquares(1_000)) prints the answer.

Check it worked

You see three timing lines and then 333833500. The numbers differ from machine to machine, but the pattern looks something like this:

Text
  0.024191 seconds (82.58 k allocations: 4.196 MiB, 99.94% compilation time)
  0.000006 seconds (1 allocation: 16 bytes)
  0.011340 seconds (28.03 k allocations: 1.478 MiB, 99.76% compilation time)
333833500

The first call is thousands of times slower than the second, and almost all of it is compilation. The Int32 call compiles again, because it is a new argument type. In a long program the compile cost is paid once and every later call runs at full speed; in a tiny script like this one it dominates. Packages you install are precompiled and cached, which keeps that delay down for code you load with using.

Step 5 · Write a function with two methods

In most languages a function has one body. In Julia a function is a name, and you can attach several methods to it, each for different argument types. When you call it, Julia picks the method that matches the types of all the arguments together. This is multiple dispatch, and it is how Julia's own +, * and println are built. Create combine.jl:

Bash
cat > combine.jl <<'JULIA'
combine(a::Number, b::Number) = a + b
combine(a::AbstractString, b::AbstractString) = a * b

println(combine(2, 3))
println(combine(2.5, 1))
println(combine("Hello, ", "Julia"))
println(methods(combine))
JULIA
julia combine.jl

Line by line:

  • combine(a::Number, b::Number) = a + b is the first method. ::Number means "this argument must be some kind of number": an Int64, a Float64 or any other number type. Two numbers are added.
  • combine(a::AbstractString, b::AbstractString) = a * b is the second method of the same function, for two pieces of text. In Julia, * joins strings. The language chose * over + because joining text, unlike adding numbers, depends on order.
  • combine(2, 3) matches the number method and prints 5. combine(2.5, 1) mixes a Float64 and an Int64; both are numbers, so the same method runs and prints 3.5.
  • combine("Hello, ", "Julia") matches the string method and prints Hello, Julia.
  • methods(combine) lists every method the function has.

You did not write an if that checks types. Julia chose the method for you, and compiled a fast version for each combination of types it met. Base Julia's own + works the same way, with well over a hundred methods.

Check it worked

The script prints 5, 3.5 and Hello, Julia, then a summary that starts with something like # 2 methods for generic function "combine" and lists both methods with the file and line each was defined on.

Step 6 · Give a project its own environment

An environment is a folder whose Project.toml file lists the packages a project uses, and whose Manifest.toml records the exact versions installed. Two projects with separate environments cannot break each other by upgrading a shared package. Make a project folder and add Example, a tiny package the Julia team maintains for demonstrations:

Bash
mkdir -p ~/hello-julia-demo/greeter
cd ~/hello-julia-demo/greeter
julia -e 'using Pkg; Pkg.activate("."); Pkg.add(name="Example", version="0.5.5")'
cat Project.toml
  • using Pkg loads Julia's built-in package manager.
  • Pkg.activate(".") makes the current folder the active environment. The folder has no Project.toml yet, so Julia reports that it is activating a new project.
  • Pkg.add(name="Example", version="0.5.5") downloads Example version 0.5.5 into your package store, ~/.julia, and records it in this folder's Project.toml and Manifest.toml. The first add on a new install also downloads the General registry, the index of public packages, which is a small download.

On Windows, quoting a -e command in PowerShell is awkward. Use the REPL instead: run julia inside the greeter folder, press ], and type activate . and then add Example@0.5.5. The prompt changes from (@v1.13) pkg> to (greeter) pkg> once the folder is active.

Now use the package from a script:

Bash
cat > greet.jl <<'JULIA'
using Example

println(hello("Julia"))
println(domath(10))
JULIA
julia --project=. greet.jl
  • using Example loads the package and brings its exported functions, hello and domath, into the script.
  • hello("Julia") returns the text Hello, Julia. domath(10) returns 10 + 5.
  • julia --project=. greet.jl runs the script with this folder as the active environment, which has the same effect as calling Pkg.activate(".") at the top. Without --project=., Julia looks in the default environment, where Example is not installed, and stops with an error that the package is not found.

Check it worked

cat Project.toml shows a [deps] section with the line Example = "7876af07-990d-54b4-ab0e-23690620f79a": the package's name and its permanent ID. ls shows both Project.toml and Manifest.toml. Running the script prints Hello, Julia and 15.

Step 7 · Fix the errors beginners hit

No method matching. Calling a function with types none of its methods accept is a MethodError, not a crash in your code. Go back to the main folder and try mixing a number and text:

Bash
cd ~/hello-julia-demo
cat > mixed.jl <<'JULIA'
include("combine.jl")
combine(2, "apples")
JULIA
Bash
julia mixed.jl

include("combine.jl") runs the earlier file, so its output appears first. Then Julia stops with MethodError: no method matching combine(::Int64, ::String) and lists the closest methods it has. The fix is to call it with matching types, or to add a method for that combination.

Index 0 does not exist. Arrays start at 1, so xs[0] is an error:

Bash
julia -e 'xs = [10, 20, 30]; xs[0]'

Julia reports BoundsError: attempt to access 3-element Vector{Int64} at index [0]. Use xs[1] for the first element and xs[end] for the last.

Single quotes are for one character. 'a' is a single character (type Char); text needs double quotes. Writing println('Hello') stops with a parse error saying the character literal contains multiple characters:

Bash
julia -e "println('Hello')"

Joining text with +. "Hello, " + "Julia" is a MethodError, because + has no method for two strings. Use *, or interpolation: "Hello, $name".

When you have finished, remove the practice folder:

Bash
cd ~
rm -rf ~/hello-julia-demo

Packages stay in ~/.julia and are reused by later projects. To remove Julia itself, run juliaup self uninstall.

Check it worked

mixed.jl stops with MethodError: no method matching combine(::Int64, ::String), xs[0] reports a BoundsError, and 'Hello' gives a parse error. Each one runs once you make the fix described above it.

Next steps

  • See the language Julia is most often compared with for statistics and data work: Hello World in R.
  • Try the same first steps in Python, the most common language for data and machine learning: Hello World in Python.
  • Meet the compiled language that numerical computing grew up on, which also counts arrays from 1: Hello World in Fortran.

Need this done for you?

Padding does this work for growing companies, from the first diagnosis to a system that keeps working.

Platform Engineering

Get new tutorials

New tutorials, about twice a month.