Julia Package Manager
Julia's built-in package manager, Pkg, installs packages from the General registry (more than 10,000 packages), manages versions, and keeps a separate environment per project so different projects can use different package versions. Package code can't run in this site's playgrounds, so the examples in this lesson are shell and REPL sessions.
Pkg mode
Press ] at the julia> prompt to enter Pkg mode. The prompt shows the active environment:
julia> ]
(@v1.11) pkg> add DataFrames CSV
Resolving package versions...
Updating `~/.julia/environments/v1.11/Project.toml`
[a93c6f00] + DataFrames v1.7.0
[336ed68f] + CSV v0.10.15
(@v1.11) pkg> status
Status `~/.julia/environments/v1.11/Project.toml`
[336ed68f] CSV v0.10.15
[a93c6f00] DataFrames v1.7.0Press Backspace to return to the Julian prompt. The same operations are available as functions, which is handy in scripts:
using Pkg
Pkg.add("DataFrames")
Pkg.add(name="CSV", version="0.10")
Pkg.status()Common commands
| Pkg-mode command | Function form | What it does |
|---|---|---|
add Name |
Pkg.add("Name") |
install a package into the active environment |
rm Name |
Pkg.rm("Name") |
remove it |
up / update |
Pkg.update() |
upgrade packages within compatibility bounds |
status / st |
Pkg.status() |
list installed packages |
activate path |
Pkg.activate("path") |
switch to another environment |
instantiate |
Pkg.instantiate() |
install exactly what a project's manifest lists |
pin Name / free Name |
Pkg.pin, Pkg.free |
freeze / unfreeze a version |
dev path |
Pkg.develop(path=...) |
use a local checkout of a package |
test Name |
Pkg.test("Name") |
run a package's tests |
gc |
Pkg.gc() |
delete unused package versions |
Environments: Project.toml and Manifest.toml
An environment is a folder with two files:
- Project.toml lists the packages you depend on directly (and optional compatibility bounds).
- Manifest.toml records the exact versions of every package, including indirect dependencies. Committing it lets anyone reproduce your environment precisely.
# Project.toml
name = "WeatherReport"
uuid = "4c1d9f3a-7b1e-4a52-9c61-2d0b6e3f8a11"
version = "0.1.0"
[deps]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
[compat]
julia = "1.10"
DataFrames = "1.6"Create and use a project environment like this:
$ mkdir weather && cd weather
$ julia --project=. # start Julia with ./Project.toml as the active environment(weather) pkg> add CSV DataFrames
(weather) pkg> statusSomeone who clones the project runs julia --project=. -e 'using Pkg; Pkg.instantiate()' to get identical packages.
Tip: Avoid installing everything into the default
@v1.11environment. Give each project its own environment; keep only general tools (likeReviseorBenchmarkTools) in the default one.
Using a package
After installing, load it with using or import, exactly like the standard library modules:
using DataFrames
df = DataFrame(city = ["Oslo", "Rome", "Lima"], temp = [4.5, 18.0, 22.1])
filter(row -> row.temp > 10, df)2×2 DataFrame
Row │ city temp
│ String Float64
─────┼─────────────────
1 │ Rome 18.0
2 │ Lima 22.1The standard library
Some modules ship with Julia, so they need no installation (though inside a project environment you still add them to declare the dependency). These all work in this site's playgrounds:
using Statistics, LinearAlgebra, Printf, Random, Dates
@printf("mean = %.2f\n", mean([2, 4, 9]))
println(det([2 1; 1 3]))
println(rand(MersenneTwister(42), 1:6, 3))
println(Date(2025, 3, 14) + Day(7))
println(VERSION >= v"1.11")mean = 5.00
5.0
[2, 6, 3]
2025-03-21
true
Popular packages
| Area | Packages |
|---|---|
| Data frames & files | DataFrames, CSV, Arrow, XLSX |
| Plotting | Plots, Makie, AlgebraOfGraphics |
| Machine learning | Flux, MLJ, Lux |
| Differential equations | DifferentialEquations |
| Optimisation | JuMP, Optim |
| Statistics | StatsBase, Distributions, GLM, HypothesisTests |
| Development | Revise, BenchmarkTools, Documenter |
| Notebooks | Pluto, IJulia |
Creating your own package
(@v1.11) pkg> generate Greeter
Generating project Greeter:
Greeter/Project.toml
Greeter/src/Greeter.jlsrc/Greeter.jl contains a module named Greeter. Activate the folder (activate Greeter) and using Greeter loads it. Tools like PkgTemplates.jl generate a full package with tests, CI and documentation set up.
Test yourself
Which file records the exact versions of all dependencies, including indirect ones?
- Project.toml
- Manifest.toml
- Packages.jl
- requirements.txt
How do you install all packages listed by a cloned project?
- Pkg.update()
- Pkg.instantiate() in that project's environment
- Pkg.build()
- include("Project.toml")
What does julia --project=. do?
- Creates a new package
- Starts Julia with the current folder as the active environment
- Runs all tests
- Updates Julia