Skip to content
Tutorials Center
My learning

Topics

Lesson 2 of 40 ยท Getting Started

Installing Julia and Using the REPL

Install Julia with juliaup, learn the four REPL modes (julia>, help?>, shell> and pkg>), run script files and set up VS Code or a notebook.

To learn Julia you need it on your own computer, because this site shows Julia code read-only. The good news is that installation takes a minute, and the tool you will spend most of your time in, the REPL, is one of the nicest in any language. REPL stands for read-eval-print loop: you type an expression, Julia evaluates it and prints the result.

This lesson covers installing Julia with juliaup, the four REPL modes, running scripts from files and choosing an editor. Everything here is read-only because it happens on your machine, but the stand-ins at the end let you practice the mode switching idea.

Installing with juliaup

The recommended way to install Julia is juliaup, a small version manager. It installs Julia, keeps it up to date and lets you switch between versions.

TEXT
# Windows (Microsoft Store or winget)
winget install --name Julia --id 9NJNWW8PVKMN -e -s msstore

# macOS and Linux
curl -fsSL https://install.julialang.org | sh

After installing, open a new terminal and start Julia by typing julia. Useful juliaup commands:

TEXT
juliaup status            # show installed channels
juliaup add lts           # install the long-term-support release
juliaup default release   # make the newest stable release the default
juliaup update            # update all installed channels

A channel is a named release line such as release (newest stable), lts (long-term support) or nightly. You can also download an installer from julialang.org, but juliaup is easier to keep current.

Starting the REPL

Typing julia gives you a banner and a prompt:

TEXT
$ julia
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.x (the version you installed)
 _/ |\__'_|_|_|\__'_|  |
|__/                   |

julia>

The prompt julia> means you are in normal mode. Type an expression and press Enter:

JULIA
julia> 2 + 3
5

julia> x = 10
10

julia> x * 2
20

julia> ans
20

The special variable ans holds the last result. If you end a line with a semicolon, Julia runs it but hides the output, which is handy for large arrays: y = collect(1:10_000);.

To quit, press Ctrl+D or type exit().

The four REPL modes

The most distinctive feature of the Julia REPL is that single keys at the start of an empty line switch the prompt into a different mode. The prompt text tells you where you are.

One REPL, four modes

julia> Normal mode. Run Julia code.
help?> Press ? to read documentation.
shell> Press ; to run shell commands.
pkg> Press ] to manage packages.

Press Backspace on an empty line to return to julia>.

1 / 2

Help mode

Press ? on an empty line and type a name:

JULIA
help?> println
search: println printstyled print sprint pointer

  println([io::IO], xs...)

  Print (using print) xs to io followed by a newline. ...

Help mode also searches: typing part of a name lists matches. It works for your own functions too, if you give them docstrings.

Shell mode

Press ; to run an operating-system command without leaving Julia:

TEXT
shell> ls
shell> pwd

Inside normal code, you run commands with backticks, for example run(echo hello). Shell mode is just the interactive shortcut.

Package mode

Press ] to manage packages (the next chapters cover this in detail):

TEXT
(@v1.x) pkg> add Plots
(@v1.x) pkg> status
(@v1.x) pkg> update
(@v1.x) pkg> rm Plots

The text before pkg> is the active environment. @v1.x is the default global environment for your Julia version. Prefer a project-specific environment, as explained in Packages and Environments.

You can also use the same operations from code with using Pkg; Pkg.add("Plots").

History and completion

  • Up and down arrows walk through history, even across sessions.
  • Tab completes names. Typing pri then Tab offers print, println and others.
  • Type a backslash name and press Tab to enter Unicode: \alpha + Tab gives ฮฑ, \pi + Tab gives ฯ€, x\_1 + Tab gives xโ‚.
  • Ctrl+C interrupts a running computation.

Running scripts

A script is a text file with Julia code, conventionally ending in .jl. Suppose hello.jl contains one line:

JULIA
println("Hello from a script")

Run it from the terminal:

TEXT
julia hello.jl

Or include it from the REPL:

JULIA
julia> include("hello.jl")
Hello from a script

You can pass command-line arguments. Inside the script they appear in the global array ARGS:

JULIA
# args.jl
println("Got ", length(ARGS), " arguments: ", ARGS)
TEXT
julia args.jl one two
# Got 2 arguments: ["one", "two"]

Useful julia flags: -e "println(1+1)" runs a one-liner, --project activates the environment in the current folder, -t 4 starts four threads (see Threads, Tasks and Distributed Computing), and -i keeps the REPL open after running a script.

A good workflow is to start the REPL once and keep it open all day. Julia compiles code on first use, so a long-lived session avoids paying that start-up cost repeatedly. The Revise package then reloads your changes automatically; see Debugging and Profiling.

Choosing an editor

You can use any editor, but these are the common choices:

  • VS Code with the Julia extension. The most popular choice. It gives syntax highlighting, an integrated REPL, a debugger, a plot pane and inline results.
  • Pluto notebooks. A reactive notebook: change a cell and every cell that depends on it updates. Good for teaching and exploration. Install with ] add Pluto, then using Pluto; Pluto.run().
  • Jupyter. Julia works in Jupyter through the IJulia package (] add IJulia). The "Ju" in Jupyter even comes from Julia, alongside Python and R.
  • Terminal editors such as Vim, Emacs or Helix, with the REPL in a second window.

Practicing the modes with a stand-in

The site cannot start Julia, but you can simulate how the REPL decides what a line means. This Python function inspects the first character of a line, exactly the rule the real REPL uses on an empty prompt, and returns the mode it would enter.

Python Which REPL mode? (analogy)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

In the real REPL the switch only happens when the line is empty. Typing ] in the middle of an expression, such as inside a[1], is just a normal character.

The next stand-in parses simple Pkg commands, to show how add, rm and status change a set of installed packages.

Python A tiny package manager (analogy)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The real Pkg also resolves versions, downloads and precompiles packages and records everything in Project.toml and Manifest.toml. This sketch only tracks names.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. What is juliaup?

    juliaup installs Julia, keeps it up to date and lets you switch between release channels such as release, lts and nightly.
  2. 2. Which key, pressed on an empty line, switches the REPL to package mode?

    ] enters Pkg mode, ? enters help mode and ; enters shell mode. Backspace on an empty line returns to julia>.
  3. 3. What does ending a REPL line with a semicolon do?

    The semicolon suppresses output. The expression still runs, and the result is still stored in ans.
  4. 4. How do you run the file hello.jl from a terminal?

    julia hello.jl starts Julia, runs the file and exits. From inside the REPL you can use include("hello.jl").
  5. 5. How can you type the Greek letter ฮฑ in the REPL?

    Julia supports LaTeX-style Unicode entry. Type the backslash name and press Tab to replace it with the symbol.

Summary

  • Install Julia with juliaup and start it by typing julia.
  • The REPL prompt changes by mode: julia> for code, help?> after ?, shell> after ;, and pkg> after ].
  • A trailing semicolon hides output, ans holds the last result, and Tab completes names and Unicode symbols.
  • Run scripts with julia file.jl or include("file.jl"); arguments arrive in ARGS.
  • VS Code with the Julia extension, Pluto and Jupyter are the common working environments.
  • Keep one REPL open to avoid repeating compile time.

Next, write real code in Your First Julia Program.