You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/lecture_06/pkg.md
+74-15Lines changed: 74 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Package management
2
2
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
4
4
5
5
```julia
6
6
(@v1.5) pkg>
@@ -12,13 +12,19 @@ Registered packages can be installed using the `add` keyword in the following wa
12
12
(@v1.5) pkg> add JSON BSON
13
13
```
14
14
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
The `status` keyword or its shorthand `st` can be used to list all installed packages.
22
28
23
29
```julia
24
30
(@v1.5) pkg> st
@@ -28,13 +34,70 @@ Status `~/.julia/environments/v1.5/Project.toml`
28
34
[682c06a0] JSON v0.21.1
29
35
```
30
36
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.
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
32
73
33
74
```julia
34
75
(@v1.5) pkg> update Example
35
76
```
36
77
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
+
```
38
101
39
102
Any installed package can be removed using the `rm` keyword similarly as the installation works
40
103
@@ -61,22 +124,14 @@ Updating and removing a package can be done in a similar way.
61
124
</p></div>
62
125
```
63
126
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.
74
129
75
130
## Enviroments
76
131
77
132
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.
78
133
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
80
135
81
136
```julia
82
137
julia> mkdir("./tutorial") # create an empty folder tutorial
@@ -123,3 +178,7 @@ julia> readdir("./tutorial")
123
178
```
124
179
125
180
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.
0 commit comments