Skip to content

Commit 32f1039

Browse files
committed
Finished pkg.md
1 parent 202ec3e commit 32f1039

File tree

1 file changed

+74
-15
lines changed

1 file changed

+74
-15
lines changed

docs/src/lecture_06/pkg.md

Lines changed: 74 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Package management
22

3-
Julia provides a simple and intuitive built-in package manager [Pkg.jl](https://julialang.github.io/Pkg.jl/v1/), that handles operations such as installing, updating, and removing packages. The package manager provides an interactive Pkg REPL, which simplifies the package management process. The Pkg REPL can be entered from the Julia REPL simply by pressing `]`. To get back to the Julia REPL, press backspace or `^C`. After entering the Pkg REPL, the screen similar to the following one should appear
3+
Julia provides a simple and intuitive built-in package manager, that handles operations such as installing, updating, and removing packages. The package manager provides an interactive Pkg REPL, which simplifies the package management process. The Pkg REPL can be entered from the Julia REPL simply by pressing `]`. To get back to the Julia REPL, press backspace or `^C`. After entering the Pkg REPL, the screen similar to the following one should appear
44

55
```julia
66
(@v1.5) pkg>
@@ -12,13 +12,19 @@ Registered packages can be installed using the `add` keyword in the following wa
1212
(@v1.5) pkg> add JSON BSON
1313
```
1414

15-
Note that it is possible to install multiple packages at once simply by entering their names separated by a space. It is also possible to install the unregistered package using the `add` keyword. However, in this case, we have to specify the package URL
15+
Note that it is possible to install multiple packages at once simply by entering their names separated by a space. It is also possible to install the unregistered package using the `add` keyword. However, in this case, we have to specify an URL of a git repository
1616

1717
```julia
1818
(@v1.5) pkg> add https://github.com/JuliaLang/Example.jl
1919
```
2020

21-
To list all installed packages, we can use the `status` keyword or its shorthand `st`
21+
or absolute/relative path to the local git repository
22+
23+
```julia
24+
(@v1.5) pkg> add /absolute/or/relative/path/MyPackage
25+
```
26+
27+
The `status` keyword or its shorthand `st` can be used to list all installed packages.
2228

2329
```julia
2430
(@v1.5) pkg> st
@@ -28,13 +34,70 @@ Status `~/.julia/environments/v1.5/Project.toml`
2834
[682c06a0] JSON v0.21.1
2935
```
3036

37+
```@raw html
38+
<div class = "info-body">
39+
<header class = "info-header">Adding specific version</header><p>
40+
```
41+
42+
In most cases, we want to install the latest stable version of the package. However, it may occur that we want to use the older version of the package or the version from a different git branch that is not yet released. A specific version of the package can be installed by appending a version after a `@` symbol.
43+
44+
```julia
45+
(@v1.5) pkg> add BSON@0.2.1
46+
47+
(@v1.5) pkg> st
48+
Status `~/.julia/environments/v1.5/Project.toml`
49+
[fbb218c0] BSON v0.2.1
50+
[7876af07] Example v0.5.4 `https://github.com/JuliaLang/Example.jl#master`
51+
[682c06a0] JSON v0.21.1
52+
```
53+
54+
If a branch (or a certain commit) of the package has a hotfix that is not yet included in a registered version, we can explicitly track that branch (or commit) by appending `#branchname` (or `#commitSHA1`) to the package name.
55+
56+
```julia
57+
(@v1.5) pkg> add BSON#master
58+
59+
(@v1.5) pkg> add JSON#1231b521196de6697d682940b963167fbe4d5cd8
60+
61+
(@v1.5) pkg> st
62+
Status `~/.julia/environments/v1.5/Project.toml`
63+
[fbb218c0] BSON v0.3.2 `https://github.com/JuliaIO/BSON.jl.git#master`
64+
[7876af07] Example v0.5.4 `https://github.com/JuliaLang/Example.jl#master`
65+
[682c06a0] JSON v0.21.1+ `https://github.com/JuliaIO/JSON.jl.git#1231b52`
66+
```
67+
68+
```@raw html
69+
</p></div>
70+
```
71+
3172
If we want to update some package (for example, because the new version was released), we can do it using the `update` keyword followed by the package name
3273

3374
```julia
3475
(@v1.5) pkg> update Example
3576
```
3677

37-
If the package name is not provided, all installed packages will be updated. Note that, in this case, even the unregistered packages are update based on their name. The difference between managing the registered and the unregistered package is only during installation.
78+
Note that, in this case, even the unregistered packages are update based on their name. The difference between managing the registered and the unregistered package is only during installation. If the package name is not provided, all installed packages will be updated. Sometimes it is very useful to disallow updating of some package. It can be done using the `pin` command. A pinned package will never be updated.
79+
80+
```julia
81+
(@v1.5) pkg> pin Example BSON
82+
83+
(@v1.5) pkg> st
84+
Status `~/.julia/environments/v1.5/Project.toml`
85+
[fbb218c0] BSON v0.3.2
86+
[7876af07] Example v0.5.4 `https://github.com/JuliaLang/Example.jl#master`
87+
[682c06a0] JSON v0.21.1
88+
```
89+
90+
Note the pin symbol `` showing that the package is pinned. Removing the pin is done using the `free` command
91+
92+
```julia
93+
(@v1.5) pkg> free BSON
94+
95+
(@v1.5) pkg> st
96+
Status `~/.julia/environments/v1.5/Project.toml`
97+
[fbb218c0] BSON v0.3.2
98+
[7876af07] Example v0.5.4 `https://github.com/JuliaLang/Example.jl#master`
99+
[682c06a0] JSON v0.21.1
100+
```
38101

39102
Any installed package can be removed using the `rm` keyword similarly as the installation works
40103

@@ -61,22 +124,14 @@ Updating and removing a package can be done in a similar way.
61124
</p></div>
62125
```
63126

64-
```@raw html
65-
<div class = "info-body">
66-
<header class = "info-header">JuliaHub</header><p>
67-
```
68-
69-
[JuliaHub](https://juliahub.com) is a web service provided by [Julia Computing](https://juliacomputing.com/) that allows you to explore the ecosystem, build packages, and run code in the cloud on large machines and clusters on demand. The most important feature for beginners is the possibility to explore packages, documentation, repositories, or codes in a simple unified way.
70-
71-
```@raw html
72-
</p></div>
73-
```
127+
``` warning "JuliaHub"
128+
[JuliaHub](https://juliahub.com) is a web service provided by [Julia Computing](https://juliacomputing.com/) that allows you to explore the ecosystem, build packages, and run code in the cloud on large machines and clusters on demand. The most important feature for beginners is the possibility to explore packages, documentation, repositories, or codes in a simple unified way.
74129
75130
## Enviroments
76131
77132
So far, we have dealt with the basic management of packages: adding, updating, or removing packages. However, Julia's package manager offers significant advantages over traditional package managers by organizing dependencies into environments. Environments should be familiar to people who use Python. The difference between Python and Julia is that it is effortless to create and manage environments in Julia. Of course, some utilities simplify the work with environments in Python, such as the Conda package manager. However, in Julia, it is still more convenient, and the whole process of creating and managing environments can be done within Julia itself.
78133
79-
You may have noticed the (`v1.5`) in the REPL prompt. It indicates that the active environment is `v1.5`. The active environment is the environment that will be modified by `Pkg` commands such as `add`, `rm` or `update`. A new environment can be set up using the `activate` keyword followed by the absolute or relative path
134+
You may have noticed the (`v1.5`) in the REPL prompt. It indicates that the active environment is `v1.5`. The active environment is the environment that will be modified by `Pkg` commands such as `add`, `rm` or `update`.A new environment can be set up using the `activate` keyword followed by the absolute or relative path
80135
81136
```julia
82137
julia> mkdir("./tutorial") # create an empty folder tutorial
@@ -123,3 +178,7 @@ julia> readdir("./tutorial")
123178
```
124179

125180
The `Project.toml` describes the project on a high level. For example, the package/project dependencies and compatibility constraints are listed in the `Project.toml` file. The `Manifest.toml` file is an absolute record of the state of the packages used in the environment. It includes exact information about (direct and indirect) dependencies of the project. Given a `Project.toml` + `Manifest.toml` pair, it is possible to [instantiate](https://julialang.github.io/Pkg.jl/v1/api/#Pkg.instantiate) the exact same package environment, which is very useful for reproducibility.
181+
182+
```julia
183+
(tutorial) pkg> instantiate
184+
```

0 commit comments

Comments
 (0)