Here is a list of steps to be followed:
- Go to the Julia command line:
julia>
- Press ] to switch to the package manager mode:
(v1.0) pkg>
- We can check the initial status of packages using the status command:
(v1.0) pkg> status
Status `~/.julia/environments/v1.0/Project.toml`
We can see that we currently have a clean environment with no additional packages installed.
- To add the BenchmarkTools package, use the add command:
(v1.0) pkg> add BenchmarkTools
Cloning default registries into /home/ubuntu/.julia/registries
Cloning registry General from "https://github.com/JuliaRegistries/General.git"
Updating registry at `~/.julia/registries/General`
Updating git-repo `https://github.com/JuliaRegistries/General.git`
Resolving package versions...
Installed BenchmarkTools ─ v0.4.1
Installed JSON ─────────── v0.19.0
Updating `~/.julia/environments/v1.0/Project.toml`
[6e4b80f9] + BenchmarkTools v0.4.1
Updating `~/.julia/environments/v1.0/Manifest.toml`
[6e4b80f9] + BenchmarkTools v0.4.1
[682c06a0] + JSON v0.19.0
[2a0f44e3] + Base64
[ade2ca70] + Dates
[8ba89e20] + Distributed
[b77e0a4c] + InteractiveUtils
[76f85450] + LibGit2
[8f399da3] + Libdl
[37e2e46d] + LinearAlgebra
[56ddb016] + Logging
[d6f4376e] + Markdown
[a63ad114] + Mmap
[44cfe95a] + Pkg
[de0858da] + Printf
[3fa0cd96] + REPL
[9a3f8284] + Random
[ea8e919c] + SHA
[9e88b42a] + Serialization
[6462fe0b] + Sockets
[2f01184e] + SparseArrays
[10745b16] + Statistics
[8dfed614] + Test
[cf7118a7] + UUIDs
[4ec0a83e] + Unicode
- Now, use the status command to see the versions of your installed packages:
(v1.0) pkg> status
Status `~/.julia/environments/v1.0/Project.toml`
[6e4b80f9] BenchmarkTools v0.4.1
Notice that only the BenchmarkTools package is visible, although more packages have been installed by Julia. They reside in the package repository but are not visible to the user unless explicitly installed. Those packages are dependencies of the BenchmarkTools package (directly or via recursive dependency).
- After installing a package, we precompile the installed packages:
(v1.0) pkg> precompile
Precompiling project...
Precompiling BenchmarkTools
[ Info: Precompiling BenchmarkTools [6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf]
- Exit the package manager mode by pressing the Backspace key:
(v1.0) pkg>
julia>
- Now, we can check that the package can be loaded and used:
julia> using BenchmarkTools
julia> @btime rand()
4.487 ns (0 allocations: 0 bytes)
0.07253910317708079
- Finally, install the BSON package version v0.2.0 (this is not the latest version of this package, as as of writing of the book the currently released version is v0.2.1). Switch to the PackageManager mode by pressing ] and then type:
(v1.0) pkg> add [email protected]
[output is omitted]
Now you have version 0.2.0 of the BSON package installed
- Often you want to keep the version of some package fixed to avoid its update by the Julia Package Manager, when its new version is released. You can achieve it with the pin command as follows
(v1.0) pkg> pin BSON
[output is omitted]
- If you decide that you want to allow the Julia Package Manager to update some package that was pinned you can do it using the free command:
(v1.0) pkg> free BSON
[output is omitted]
The process of installing a specified version of some package (step 9 of the recipe) and pinning it (step 10) might be useful for you when you will need to install the exact versions of the packages that we use in this book, as in the future new releases of the packages might introduce breaking changes. The full list of packages used in this book along with their required versions is given in the To get the most out of this book section in the Preface of this book. Â