Introduction to the Julia programming language
13 Package Management¶
Managing Julia Packages (Pkg)¶
Managing Julia packages is a crucial aspect of working with the Julia programming language. Packages in Julia are collections of code that extend the language's functionality beyond its core features. They can be libraries, tools, or applications developed by the community or individuals to solve specific problems or provide additional capabilities.
Packages are registered in the Julia General Registry, and can be browsed with tools like Julia Packages.
The Pkg "environment"¶
Pkg is also one of two components of Julia which have their own sub-environments within the REPL (the other being the help functionality).
Pressing ]
in a Julia REPL switches to the Pkg environment, where all commands are issued to Pkg directly.
Hence
using Pkg
Pkg.add("PackageName")
is the same as
add foo
within the Pkg sub environment.
Pressing backspace on an empty prompt exits the environment and returns to Julia proper.
Show installed packages¶
Air-von-Klaus:notebooks reygers$ julia
_
_ _ _(_)_ | Documentation: https://docs.julialang.org
(_) | (_) (_) |
_ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 1.10.2 (2024-03-01)
_/ |\__'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |
(@v1.10) pkg> status
Status `~/.julia/environments/v1.10/Project.toml`
[336ed68f] CSV v0.10.13
[59287772] Formatting v0.4.3
[7073ff75] IJulia v1.24.2
[a09fc81d] ImageCore v0.10.2
[82e4d734] ImageIO v0.6.7
[d8c32880] ImageInTerminal v0.5.2
[4e3cecfd] ImageShow v0.3.8
[23fbe1c1] Latexify v0.16.2
[2fda8390] LsqFit v0.15.0
[eff96d63] Measurements v2.11.0
[429524aa] Optim v1.9.4
[91a5bcdd] Plots v1.40.3
[f3b207a7] StatsPlots v0.15.7
[0c5d862f] Symbolics v5.27.1
[009559a3] XGBoost v2.5.1
Updating and removing packages¶
Updating Packages:
Pkg.update()
Removing Packages:
Pkg.rm("PackageName")
Managing Environments¶
Pkg
allows you to work with different environments to isolate package installations. You can create a new environment using the generate command:
Pkg.generate("MyEnvironment")
Pkg.activate("MyEnvironment")
Working with Project Files¶
Julia supports project files (Project.toml and Manifest.toml) to manage dependencies for your projects. You can create a new project using the generate
command:
Pkg.generate("MyProject"; force = true)
This command initializes a new project in the current directory.