Skip to content
Snippets Groups Projects
Code owners
Assign users and groups as approvers for specific file changes. Learn more.

Bootstrapping Julia

Installing Julia

Recommended method:

Distribution packages usually work well too:

  • Debians&Ubuntus: apt install julia
  • Iris/Aion: module add lang/Julia

Life in REPL

user@pc $ julia

julia> sqrt(1+1)
1.4142135623730951

julia> println("Well hello there!")
Well hello there!

julia> ?
help?> sqrt

sqrt(x)

Computes the square root .....

REPL modes

Julia interprets some additional keys to make our life easier:

  • ?: help mode
  • ;: shell mode
  • ]: packaging mode (looks like a box!)
  • Backspace: quits special mode
  • Tab: autocomplete anything
  • \... Tab: expand math characters

Managing packages from the package management environment

  • Install a package
] add UnicodePlots
  • Uninstall a package
] remove UnicodePlots

Loading libraries, modules and packages

  • Load a local file (with shared functions etc.)
include("mylibrary.jl")
  • Load a package, add its exports to the global namespace
using UnicodePlots

How to write a standalone program?

Your scripts should communicate well with the environment! (that means, among other, you)

#!/usr/bin/env julia

function process_file(filename)

  @info "Processing $filename..."

  # ... do something ...

  if error_detected
    @error "something terrible has happened"
    exit(1)
  end
end

for file in ARGS
    process_file(file)
end

Correct processing of commandline arguments makes your scripts repurposable and configurable.

Workflow: Make a local environment for your script

  • Enter a local project with separate package versions
] activate path/to/project
  • Install dependencies of the local project
] instantiate
  • Execute a script with the project environment
$ julia --project=path/to/project script.jl

(Project data is stored in Project.toml, Manifest.toml.)