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
+14-13Lines changed: 14 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -1,24 +1,24 @@
1
1
# Package management
2
2
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
3
+
Julia provides a simple and intuitive built-in package manager that handles operations such as installing, updating, and removing packages. The package manager offers 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>
7
7
```
8
8
9
-
Registered packages can be installed using the `add` keyword in the following way
9
+
Registered packages can be installed using the `add` keyword in the following way.
10
10
11
11
```julia
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 an URL of a git repository
15
+
Note that it is possible to install multiple packages 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.
@@ -39,7 +39,7 @@ Status `~/.julia/environments/v1.5/Project.toml`
39
39
<header class = "info-header">Adding specific version</header><p>
40
40
```
41
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.
42
+
In most cases, we want to install the latest stable version of the package. However, we may 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
43
44
44
```julia
45
45
(@v1.5) pkg> add BSON@0.2.1
@@ -69,7 +69,7 @@ Status `~/.julia/environments/v1.5/Project.toml`
69
69
</p></div>
70
70
```
71
71
72
-
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
72
+
If we want to update some packages (for example, because the new version was released), we can do it using the `update` keyword followed by the package name.
73
73
74
74
```julia
75
75
(@v1.5) pkg> update Example
@@ -87,7 +87,7 @@ Status `~/.julia/environments/v1.5/Project.toml`
87
87
[682c06a0] JSON v0.21.1
88
88
```
89
89
90
-
Note the pin symbol `⚲` showing that the package is pinned. Removing the pin is done using the `free` command
90
+
Note the pin symbol `⚲` showing that the package is pinned. Removing the pin is done using the `free` command.
91
91
92
92
```julia
93
93
(@v1.5) pkg> free BSON
@@ -99,7 +99,7 @@ Status `~/.julia/environments/v1.5/Project.toml`
99
99
[682c06a0] JSON v0.21.1
100
100
```
101
101
102
-
Any installed package can be removed using the `rm` keyword similarly as the installation works
102
+
Any installed package can be removed using the `rm` keyword similarly as the installation works.
103
103
104
104
```julia
105
105
(@v1.5) pkg> rm Example
@@ -110,7 +110,7 @@ Any installed package can be removed using the `rm` keyword similarly as the ins
110
110
<header class = "info-header">Non-interactive package manager</header><p>
111
111
```
112
112
113
-
The package manager can also be used in a non-interactive way. For example, packages can be installed in the following way
113
+
The package manager can also be used in a non-interactive way. For example, packages can be installed in the following way.
114
114
115
115
```julia
116
116
using Pkg
@@ -131,7 +131,7 @@ Updating and removing a package can be done in a similar way.
131
131
132
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.
133
133
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
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.
135
135
136
136
```julia
137
137
julia>mkdir("./tutorial") # create an empty folder tutorial
In the example above, we create an empty directory `tutorial` and activate a new environment inside this directory. Note that the prompt in the package REPL changed from `@v1.5` to `tutorial`. It indicates that `tutorial` is the active environment, i.e., this environment will be modified by Pkg commands. Now we can check the status of the environment using the `status` keyword
146
+
In the example above, we create an empty directory `tutorial` and activate a new environment inside this directory. Note that the prompt in the package REPL changed from `@v1.5` to `tutorial`. It indicates that `tutorial` is the active environment, i.e., this environment will be modified by Pkg commands. Now we can check the status of the environment using the `status` keyword.
147
147
148
148
```julia
149
149
(tutorial) pkg> status
150
150
Status `/tutorial/Project.toml` (empty project)
151
151
```
152
152
153
-
Note that the path printed by the `status` command (`/tutorial/Project.toml`) is the location of the `Project.toml` corresponding to the active environment. A `Project.toml` is a file where the package manager stores metadata for the environment. Because we have not yet added any packages to the environment, the `Project.toml` is not created yet
153
+
Note that the path printed by the `status` command (`/tutorial/Project.toml`) is the location of the `Project.toml` corresponding to the active environment. A `Project.toml` is a file where the package manager stores metadata for the environment. Because we have not yet added any packages to the environment, the `Project.toml` is not created yet.
154
154
155
155
```julia
156
156
julia>readdir("./tutorial") # returns and empty array since tutorial is an empty folder
157
157
String[]
158
158
```
159
159
160
-
We can install packages to the `tutorial` environment in the same way as we did it in the section above
160
+
We can install packages to the `tutorial` environment in the same way as we did it in the section above.
161
161
162
162
```julia
163
163
(tutorial) pkg> add JSON BSON
@@ -177,6 +177,7 @@ julia> readdir("./tutorial")
177
177
"Project.toml"
178
178
```
179
179
180
+
We can install packages to the `tutorial` environment in the same way as we did in the section above.
180
181
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