Skip to content

Julia Interactive Commands

Julia REPL (Read-Eval-Print Loop) is Julia's interactive command-line environment, an excellent tool for learning and experimenting with Julia code.

Starting REPL

Enter julia in terminal to start REPL:

               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.10.0 (2023-12-25)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia>

Basic Usage

Executing Expressions

Enter expressions directly and press Enter:

julia
julia> 1 + 2
3

julia> "Hello, " * "Julia!"
"Hello, Julia!"

julia> sqrt(16)
4.0

Variable Assignment

julia
julia> x = 10
10

julia> y = 20
20

julia> x + y
30

Multi-line Input

Use semicolon ; to suppress output:

julia
julia> a = 1;

julia> b = 2;

julia> a + b
3

For multi-line code, enter directly:

julia
julia> function greet(name)
           println("Hello, $name!")
       end
greet (generic function with 1 method)

julia> greet("Julia")
Hello, Julia!

REPL Modes

Julia REPL has four main modes, switched using special keys.

1. Julian Mode (Default)

Prompt: julia>

Used for executing Julia code.

2. Help Mode

Press ? to enter, prompt changes to: help?>

julia
help?> println
search: println printstyled print sprint isprint

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

  Print (using print) xs to io followed by a newline. 
  If io is not supplied, prints to the default output stream stdout.

Press Backspace to return to Julian mode.

3. Package Mode

Press ] to enter, prompt changes to: (@v1.10) pkg>

julia
(@v1.10) pkg> status
Status `~/.julia/environments/v1.10/Project.toml`
  [336ed68f] CSV v0.10.12
  [a93c6f00] DataFrames v1.6.1

Common commands:

julia
pkg> add PackageName      # Install package
pkg> rm PackageName       # Remove package
pkg> update               # Update all packages
pkg> status               # View installed packages
pkg> instantiate          # Install dependencies from Project.toml

Press Backspace to return to Julian mode.

4. Shell Mode

Press ; to enter, prompt changes to: shell>

julia
shell> pwd
/home/user

shell> ls
Documents  Downloads  julia-project

Press Backspace to return to Julian mode.

Keyboard Shortcuts

Editing Shortcuts

ShortcutFunction
Ctrl + CInterrupt current execution
Ctrl + DExit REPL (on empty line)
Ctrl + LClear screen
Ctrl + RSearch command history
/ Browse command history
TabAuto-complete

Line Editing Shortcuts

ShortcutFunction
Ctrl + AMove to line start
Ctrl + EMove to line end
Ctrl + KDelete to line end
Ctrl + UDelete to line start
Ctrl + WDelete previous word

Auto-Completion

Press Tab for auto-completion:

Function Name Completion

julia
julia> prin<Tab>
print     println   printstyled

Module Member Completion

julia
julia> using LinearAlgebra

julia> LinearAlgebra.<Tab>
BLAS         Diagonal     Factorization  ...

Unicode Completion

Julia supports Unicode characters via LaTeX-style input:

julia
julia> \alpha<Tab>
α

julia> \sqrt<Tab>


julia> \pi<Tab>
π

Common Unicode symbols:

InputResultMeaning
\alphaαGreek letter
\betaβGreek letter
\piπPi
\sqrtSquare root
\sumSum
\inElement of
\notinNot element of
\leqLess or equal
\geqGreater or equal
\neqNot equal

History

View History

Use up/down arrow keys to browse previous commands.

Search History

Press Ctrl + R to enter reverse search mode:

julia
(reverse-i-search)`pri': println("Hello")

History File

History is saved in ~/.julia/logs/repl_history.jl.

Special Variables

ans

ans stores the result of the last expression:

julia
julia> 1 + 2
3

julia> ans * 2
6

Running Scripts

Run Script in REPL

julia
julia> include("myscript.jl")

Command Line Script

bash
julia myscript.jl

With Arguments

bash
julia myscript.jl arg1 arg2

Access arguments in script:

julia
# myscript.jl
for arg in ARGS
    println(arg)
end

Startup Options

Common Command Line Options

bash
# Specify thread count
julia -t 4

# Execute expression
julia -e 'println("Hello")'

# Quiet mode (no banner)
julia -q

# Enter REPL after running script
julia -i script.jl

# Optimization level
julia -O3 script.jl

# View help
julia --help

Startup File

Julia automatically executes ~/.julia/config/startup.jl on startup:

julia
# ~/.julia/config/startup.jl
println("Welcome to Julia!")

# Customize REPL behavior
atreplinit() do repl
    # Custom REPL initialization
end

Practical Tips

1. Quick Function Testing

julia
julia> f(x) = x^2 + 2x + 1
f (generic function with 1 method)

julia> f(3)
16

julia> f.(1:5)  # Vectorized call
5-element Vector{Int64}:
  4
  9
 16
 25
 36

2. View Types

julia
julia> typeof(1)
Int64

julia> typeof(1.0)
Float64

julia> typeof("hello")
String

3. View Methods

julia
julia> methods(+)
# [Shows all methods of + operator]

4. Timing

julia
julia> @time sum(1:1000000)
  0.000001 seconds
500000500000

5. Memory Allocation

julia
julia> @allocated rand(1000)
8000

Exiting REPL

Multiple ways to exit:

julia
julia> exit()

# Or press Ctrl + D (on empty line)

Next Steps

After mastering REPL usage, continue learning:

Content is for learning and research only.