Setup Julia
Install Julia¶
Install Julia with the juliaup installer.
Alternatively, download and install Julia official binaries.
Post-install configurations¶
Auto-activate local projects¶
Set environment variable JULIA_PROJECT=@. to let Julia automatically load the closest upstream Project.toml and activate the environment.
Info
IJulia.jl, the Julia kernel for Jupyter notebooks, sets JULIA_PROJECT=@. by default. Thus, Jupyter notebooks load their local Julia environments automatically.
Warning
Loading local environments unconditionally is unsafe for untrusted sources, as shown in Nefarious.jl.
That is why Julia does not run julia --project=@. by default.
Fully utilize CPU threads¶
Set environment variable JULIA_NUM_THREADS=auto to let Julia utilize all CPU threads.
Run Python packages¶
To run Python packages in Julia (such as matplotlib for PythonPlot.jl and jupyter for IJulia.jl)
- Install micromamba, the minimal Python package manager.
- Create a conda environment, for example,
micromamba create -n juliapy jupyter matplotlib. - Set up the following environment variables
PythonCall.jldocumentationConda.jldocumentation
export CONDA_JL_HOME="${HOME}/micromamba/envs/juliapy"
export JULIA_PYTHONCALL_EXE="${CONDA_JL_HOME}/bin/python"
export JULIA_CONDAPKG_BACKEND="Null"
Load packages at REPL startup¶
Add the following lines to ~/.julia/config/startup.jl after Revise.jl and OhMyREPL.jl are installed
using Pkg: Pkg
if isinteractive()
using OhMyREPL
using Revise
catch e
@warn "Error initializing" exception=(e, catch_backtrace())
@info "Try to install OhMyREPL and Revise"
Pkg.add(["OhMyREPL", "Revise"])
end
end
For IJulia (Jupyter notebooks) to use Revise, add the following lines to ~.julia/config/startup_ijulia.jl
try
@eval using Revise
catch e
@warn "Error initializing Revise" exception=(e, catch_backtrace())
end
Or run the following commands (heredoc in Linux) to create these two files at once
mkdir -p ~/.julia/config/ && cat > ~/.julia/config/startup.jl << END
using Pkg: Pkg
if isinteractive()
using OhMyREPL
using Revise
catch e
@warn "Error initializing" exception=(e, catch_backtrace())
@info "Try to install OhMyREPL and Revise"
Pkg.add(["OhMyREPL", "Revise"])
end
end
END
mkdir -p ~/.julia/config/ && cat > ~/.julia/config/startup_ijulia.jl << END
try
@eval using Revise
catch e
@warn "Error initializing Revise" exception=(e, catch_backtrace())
end
END