TExcelTAD
Home › Julia › Julia Package Manager

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:

text
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.0

Press Backspace to return to the Julian prompt. The same operations are available as functions, which is handy in scripts:

julia
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.
toml
# 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:

bash
$ mkdir weather && cd weather
$ julia --project=.          # start Julia with ./Project.toml as the active environment
text
(weather) pkg> add CSV DataFrames
(weather) pkg> status

Someone who clones the project runs julia --project=. -e 'using Pkg; Pkg.instantiate()' to get identical packages.

Tip: Avoid installing everything into the default @v1.11 environment. Give each project its own environment; keep only general tools (like Revise or BenchmarkTools) in the default one.

Using a package

After installing, load it with using or import, exactly like the standard library modules:

julia
using DataFrames

df = DataFrame(city = ["Oslo", "Rome", "Lima"], temp = [4.5, 18.0, 22.1])
filter(row -> row.temp > 10, df)
text
2×2 DataFrame
 Row │ city    temp
     │ String  Float64
─────┼─────────────────
   1 │ Rome       18.0
   2 │ Lima       22.1

The 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:

julia · try it yourself
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

text
(@v1.11) pkg> generate Greeter
  Generating  project Greeter:
    Greeter/Project.toml
    Greeter/src/Greeter.jl

src/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?

  1. Project.toml
  2. Manifest.toml
  3. Packages.jl
  4. requirements.txt

How do you install all packages listed by a cloned project?

  1. Pkg.update()
  2. Pkg.instantiate() in that project's environment
  3. Pkg.build()
  4. include("Project.toml")

What does julia --project=. do?

  1. Creates a new package
  2. Starts Julia with the current folder as the active environment
  3. Runs all tests
  4. Updates Julia