Enhancing the Julia REPL

Table of Contents

Loading code on startup

If you have code that you want to run every time you start Julia, add it to your startup file that is located at ~/.julia/config/startup.jl. Note that you might have to first create the config folder.

A common use-case for the startup.jl file is to load packages that are crucial for your workflow. However, be cautious about adding too many packages, as this can significantly increase the loading time of your REPL and potentially pollute the global namespace. It's best to include only essential packages that you use frequently. There are however two packages I personally consider essential additions: Revise.jl and OhMyRepl.jl.

Warning: First install packages

Before adding a package to your startup.jl, first add it to your global (@v1.10) environment!

How does this work?

Julia makes use of something called stacked environments:

Stacked environments allow for adding tools to the primary environment. You can push an environment of development tools onto the end of the stack to make them available from the REPL and scripts, but not from inside packages.

Before the environment of a package or project is activated, Julia first loads your global (@v1.10) environment and evaluates the code in your startup.jl.

Enhancing the REPL experience

Revise.jl

Revise.jl will keep track of changes in loaded files and reload modified Julia code without having to start a new REPL session.

To load Revise automatically, add the following code to your startup.jl:

# Add to ~/.julia/config/startup.jl
try
    using Revise
catch e
    @warn "Error initializing Revise in startup.jl" exception=(e, catch_backtrace())
end

It is enough to add using Revise, but the try-catch statement will return a helpful error message in case something goes wrong.

VSCode

Revise is loaded as part of the Julia VSCode plugin. If you are using VSCode, adding Revise to your startup.jl isn't necessary.

OhMyRepl.jl

OhMyRepl adds many features to your REPL, among other things:

# Add to ~/.julia/config/startup.jl
atreplinit() do repl
    try
        @eval using OhMyREPL
    catch e
        @warn "Error initializing OhMyRepl in startup.jl" exception=(e, catch_backtrace())
    end
end

Other suggestions

You can also add the following to your startup.jl:

Last modified: October 09, 2024.
Website, code and notebooks are under MIT License © Adrian Hill.
Built with Franklin.jl, Pluto.jl and the Julia programming language.