ZetCode

Julia Pkg Tutorial

last modified November 18, 2026

Pkg is Julia's built-in package manager. It downloads packages from registries, records which versions a project uses, and keeps separate projects from interfering with each other. A package is a reusable library of Julia code that you load with using or import.

This tutorial explains the ] REPL mode, the everyday commands add, rm and update, and the two files that describe a project. The examples use a small sandbox project under /tmp/opencode/ so the read-only output is reproducible. Install commands are shown but not executed here, because their output depends on the network and on which versions are current. All verified examples were run with Julia 1.13.4.

Pkg and the REPL

The fastest way to use Pkg is the dedicated REPL mode. Typing ] at the Julia prompt changes the prompt to pkg>; pressing Backspace on an empty line returns to the normal Julia prompt. Every command available in this mode also has a function form in the Pkg module.

main.jl
using Pkg

# In the Julia REPL, type ] to enter Pkg mode, then:
# pkg> status
# pkg> add Example
# pkg> rm Example
# pkg> update

The lines above are commands you type interactively; they are written as comments so the file can still be run as a Julia script. The equivalent function calls are Pkg.status(), Pkg.add("Example"), Pkg.rm("Example") and Pkg.update(). Typing ? followed by a package name in Pkg mode shows help for that command. No output is shown here because these commands are interactive and change the active environment.

Inspecting the Active Project

An environment is a set of packages and versions that is active at a given time. The Pkg.project() function returns information about the current environment, including the path to its project file and its name.

main.jl
using Pkg

Pkg.activate("/tmp/opencode/jlpkgex")
println("path: ", Pkg.project().path)
println("name: ", Pkg.project().name)
println("uuid: ", Pkg.project().uuid)
println("version: ", Pkg.project().version)

The sandbox project was given the name ExampleProject, a fixed UUID and version 0.1.0. A UUID is a universally unique identifier: a 128-bit number that distinguishes this project from every other one. Pkg.activate also writes a short notice about the activated project to the terminal; that notice goes to the error stream, so it is not part of the standard output shown below. On a fresh machine the first Pkg command may install the General registry; that one-time message is omitted here too.

$ julia main.jl
path: /tmp/opencode/jlpkgex/Project.toml
name: ExampleProject
uuid: 11111111-2222-3333-4444-555555555555
version: 0.1.0

The Project.toml File

Every environment is described by a Project.toml file. It holds the project's identity and the names of its direct dependencies, which are the packages used directly by your code.

main.jl
using Pkg

Pkg.activate("/tmp/opencode/jlpkgex")
print(read(Pkg.project().path, String))

The file below declares the standard library Test as a dependency. The [deps] section maps each package name to its UUID. Pkg writes this file for you when you add or remove a package; you normally edit it only to add version constraints in a [compat] section. TOML is a simple text format for configuration files, built from key, value pairs and named sections such as [deps].

$ julia main.jl
name = "ExampleProject"
uuid = "11111111-2222-3333-4444-555555555555"
version = "0.1.0"

[deps]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

Checking Package Status

The Pkg.status() function lists the packages recorded in the active project, together with their UUID prefixes and versions when a Manifest.toml file is present.

main.jl
using Pkg

Pkg.activate("/tmp/opencode/jlpkgex")
Pkg.status()

Only Test is declared in this sandbox, so it is the only entry. The eight hexadecimal characters in brackets are the first digits of the package UUID. Because this project has no manifest yet, Pkg prints the name without a version. Status is a read-only operation, so it is safe to run at any time, and it is the quickest way to see which environment is active.

$ julia main.jl
Project ExampleProject v0.1.0
Status `/tmp/opencode/jlpkgex/Project.toml`
  [8dfed614] Test

Adding Packages

To use a package that is not part of Julia itself, add it with Pkg. In REPL mode the command is add; from Julia code use Pkg.add with a string.

main.jl
using Pkg

Pkg.add("Example")

Pkg consults the registry, resolves versions that satisfy all declared constraints, downloads the packages and writes both Project.toml and Manifest.toml. You can request a particular version with Pkg.add(name="Example", version="0.5") or install directly from a Git repository with Pkg.add(url="https://github.com/.../Example.jl"). The command is not run here: its printed output depends on network access and on which package versions are available, so no fabricated output is shown. Once installed, load the package with using Example.

Removing and Updating Packages

Packages that are no longer needed can be removed, and installed packages can be brought up to date. Both operations edit the active environment.

main.jl
using Pkg

Pkg.rm("Example")
Pkg.update()

Pkg.rm removes a direct dependency from Project.toml and prunes packages that are no longer needed from the manifest. Pkg.update re-resolves the environment and downloads newer versions that still satisfy the constraints recorded in the project file. In REPL mode the matching commands are rm Example and update. Both commands depend on the registry state and on package versions, so their output is deliberately not reproduced here.

The Manifest.toml File

While Project.toml lists direct dependencies, the Manifest.toml file records the exact resolved version of every package, including transitive dependencies — packages that your dependencies use. This makes an environment reproducible: sharing both files lets another machine recreate exactly the same package graph.

main.jl
using Pkg

Pkg.activate("/tmp/opencode/jlpkgexm")
println(sort(readdir(dirname(Pkg.project().path))))
print(read(joinpath(dirname(Pkg.project().path), "Manifest.toml"), String))

This second sandbox has a hand-written manifest, so we print it directly instead of installing anything. The [[deps.Test]] block records the package UUID and version. Real manifests are generated by Pkg and also store a hash of the resolved dependency graph. With a manifest present, Pkg.status() can display the version of each dependency.

$ julia main.jl
["Manifest.toml", "Project.toml"]
# This file is machine-generated - editing it directly is not advised

julia_version = "1.13.4"
manifest_format = "2.0"

[[deps.Test]]
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
version = "1.11.0"

Registries and Environments

A registry is a catalogue of packages: it maps package names and UUIDs to versions and to the locations of their source code. Julia's default registry is called General. Pkg can also work with private or local registries.

main.jl
using Pkg

Pkg.Registry.status()
Pkg.Registry.add("General")
Pkg.Registry.update()

Pkg.Registry.status() lists the registries you already have. Pkg.Registry.add registers a new one and Pkg.Registry.update refreshes their package lists. The output is not shown because it contains registry hashes and timestamps that change over time. By default Pkg works in the user's shared environment; call Pkg.activate(path) to switch to a project-specific environment, or Pkg.activate(@__DIR__) to use the project in the current directory. Keeping one environment per project avoids version conflicts between unrelated programs.

Best Practices for Pkg

A few habits keep projects portable and reproducible.

Source

Julia Pkg documentation

Pkg.jl documentation

This tutorial covered Julia's package manager: the ] REPL mode, inspecting an environment, reading Project.toml and Manifest.toml, and the add, rm and update commands. Modules and namespaces are explained in Julia modules, and the recommended layout for a package's tests appears in Julia testing.

Author

I am Jan Bodnar, a programmer and technical writer. I have been writing programming tutorials at ZetCode since 2007 and have published eight e-books. See about the author.

List all Julia tutorials.