Here are some tips for working with Julia efficiently.
As already elaborated inThe Julia REPL, Julia's REPL provides rich functionality that facilitates an efficient interactive workflow. Here are some tips that might further enhance your experience at the command line.
The most basic Julia workflows involve using a text editor in conjunction with thejulia
command line.
Create a file, sayTmp.jl
, and include within it
module Tmpsay_hello() = println("Hello!")# Your other definitions hereend # moduleusing .Tmp
Then, in the same directory, start the Julia REPL (using thejulia
command). Run the new file as follows:
julia> include("Tmp.jl")julia> Tmp.say_hello()Hello!
Explore ideas in the REPL. Save good ideas inTmp.jl
. To reload the file after it has been changed, justinclude
it again.
The key in the above is that your code is encapsulated in a module. That allows you to editstruct
definitions and remove methods, without restarting Julia.
(Explanation:struct
s cannot be edited after definition, nor can methods be deleted. But youcan overwrite the definition of a module, which is what we do when we re-include("Tmp.jl")
).
In addition, the encapsulation of code in a module protects it from being influenced by previous state in the REPL, protecting you from hard-to-detect errors.
There are a few ways to interact with Julia in a browser:
Whether you're at the REPL or in IJulia, you can typically improve your development experience withRevise. It is common to configure Revise to start whenever julia is started, as per the instructions in theRevise documentation. Once configured, Revise will track changes to files in any loaded modules, and to any files loaded in to the REPL withincludet
(but not with plaininclude
); you can then edit the files and the changes take effect without restarting your julia session. A standard workflow is similar to the REPL-based workflow above, with the following modifications:
Put your code in a module somewhere on your load path. There are several options for achieving this, of which two recommended choices are:
For long-term projects, usePkgTemplates:
using PkgTemplatest = Template()t("MyPkg")
This will create a blank package,"MyPkg"
, in your.julia/dev
directory. Note that PkgTemplates allows you to control many different options through itsTemplate
constructor.
In step 2 below, editMyPkg/src/MyPkg.jl
to change the source code, andMyPkg/test/runtests.jl
for the tests.
For "throw-away" projects, you can avoid any need for cleanup by doing your work in your temporary directory (e.g.,/tmp
).
Navigate to your temporary directory and launch Julia, then do the following:
pkg> generate MyPkg # type ] to enter pkg modejulia> push!(LOAD_PATH, pwd()) # hit backspace to exit pkg mode
If you restart your Julia session you'll have to re-issue that command modifyingLOAD_PATH
.
In step 2 below, editMyPkg/src/MyPkg.jl
to change the source code, and create any test file of your choosing.
Develop your package
Before loading any code, make sure you're running Revise: sayusing Revise
or follow its documentation on configuring it to run automatically.
Then navigate to the directory containing your test file (here assumed to be"runtests.jl"
) and do the following:
julia> using MyPkgjulia> include("runtests.jl")
You can iteratively modify the code in MyPkg in your editor and re-run the tests withinclude("runtests.jl")
. You generally should not need to restart your Julia session to see the changes take effect (subject to a fewlimitations).
Settings
This document was generated withDocumenter.jl version 1.8.0 onWednesday 9 July 2025. Using Julia version 1.11.6.