Setup Julia
Install Julia¶
Install Julia with the juliaup installer.
Linux/MacOS¶
curl -fsSL https://install.julialang.org | sh -s -- -y
Windows¶
winget install julia -s msstore
Alternatively, download and install Julia official binaries.
winget install JuliaLang.Julia
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.
export JULIA_PROJECT=@.
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 use all CPU threads.
export JULIA_NUM_THREADS=auto
Customize Python and Conda location¶
Point the environment variable CONDA_JL_HOME
to your Conda path. Conda.jl
and PyCall.jl
will take the preinstalled Conda instead of downloading a standalone one. For example,
export CONDA_JL_HOME="${HOME}/conda"
For PythonCall.jl
, set the following environment variables:
export JULIA_CONDAPKG_BACKEND="Null"
export JULIA_PYTHONCALL_EXE="${HOME}/conda/bin/python"
Load packages at Julia REPL startup¶
Add the following lines to ~/.julia/config/startup.jl
after Revise.jl
and OhMyREPL.jl
are installed
using Pkg: Pkg
atreplinit() do repl
try
@eval using OhMyREPL
@eval using Revise
catch e
@warn "Error initializing" exception=(e, catch_backtrace())
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
atreplinit() do repl
try
@eval using OhMyREPL
@eval using Revise
catch e
@warn "Error initializing" exception=(e, catch_backtrace())
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