A new package manager (Pkg) was introduced with Julia 1.0. It behaves similar to virtualenv or anaconda in the Python universe.

Projects vs. Packages vs. Applications:

Project is an umbrella term: packages and applications are kinds of projects.

Packages should have UUIDs, applications can have a UUIDs but don’t need them.

Applications can provide global configuration, whereas packages cannot.

Julia documentation

Default (Project)

Pkg.add("PackageName")

If we press ], then we end up in the Julia package management environment:

(v1.0) pkg> add PackageName

This works only if the package is in the Julia’s REPL. If it is not there (called unregistered package), then we have to use the path to the package. Hence, if we want to install a Julia package from GitHub, then we have to use:

(v1.0) pkg> add https://github.com/swenkel/MediaWikiAPI.jl

This outputs something like:

   Cloning git-repo `https://github.com/swenkel/MediaWikiAPI.jl`                                                                                          
  Updating git-repo `https://github.com/swenkel/MediaWikiAPI.jl`
[ Info: Assigning UUID 730ab1b7-740b-585e-8753-a07f8bf68ef2 to MediaWikiAPI
 Resolving package versions...                                                                                                                            
  Updating `~/.julia/environments/v1.0/Project.toml`                                                                                                      
  [730ab1b7] + MediaWikiAPI v0.0.0 #master (https://github.com/swenkel/MediaWikiAPI.jl)                                                                   
  Updating `~/.julia/environments/v1.0/Manifest.toml`                                                                                                     
  [730ab1b7] + MediaWikiAPI v0.0.0 #master (https://github.com/swenkel/MediaWikiAPI.jl) 

This is similar to using pip (pip install git+URL).

Further, Julia provides us with several functions to run inside the package environment:

(v1.0) pkg>

offers the following functions:

  • ? - displays the docstring of a function; same as help
  • activate - activates an environment
  • add - adds a new package
  • build - builds a package
  • dev - makes a package available for development; same as develop
  • develop- makes a package available for development; same as dev
  • free - frees a package from being pinned
  • gc - garbage collector, deletes packages that can’t be reached from any existing environment
  • generate - generates a new package
  • help - displays the docstring of a function; same as ?
  • instantiate - downloads all dependencies for the current project
  • package - unknown; no documentation provided
  • pin - pins a package to a certain version; package is marked with
  • precompile - precompiles all dependencies of the current project (by running import)
  • preview - runs a given command in preview mode; no packages will be downloaded and installed
  • remove - removes package; same as rm
  • resolve - updates package resolution and updates the manifest
  • rm- removes package; same as remove
  • st - lists all manually added packages; same as status
  • status - lists all manually added packages; same as st
  • test - tests packages according to their unit tests
  • up - updates all packages; same as update
  • update- updates all packages; same as up

Setting Up Projects

The really interesting thing with the new package management is making an environment management similar to anaconda available. Everything show before has happened inside the (v1.0) (default) project:

(v1.0) pkg>

We can setup an new environment with navigating to a folder of our choice that contains the project or create a new folder:

$ mkdir NewProject
$ cd NewProject
$ julia

Now, we can activate this project:

(v1.0) pkg> activate ./

(NewProject) pkg>

This project is empty:

(NewProject) pkg> status
    Status `~/projects/julia/NewProject/Project.toml`

Let’s add a package:

(NewProject) pkg> add DecisionTree
  Updating registry at `~/.julia/registries/General`
  Updating git-repo `https://github.com/JuliaRegistries/General.git`
 Resolving package versions...
  Updating `~/projects/julia/NewProject/Project.toml`
  [7806a523] + DecisionTree v0.8.1
  Updating `~/projects/julia/NewProject/Manifest.toml`
  [34da2185] + Compat v1.3.0
  [7806a523] + DecisionTree v0.8.1
  [6e75b9c4] + ScikitLearnBase v0.4.1
  [2a0f44e3] + Base64 
  [ade2ca70] + Dates 
  [8bb1440f] + DelimitedFiles 
  [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 
  [1a1011a3] + SharedArrays 
  [6462fe0b] + Sockets 
  [2f01184e] + SparseArrays 
  [10745b16] + Statistics 
  [8dfed614] + Test 
  [cf7118a7] + UUIDs 
  [4ec0a83e] + Unicode 

Checking the status:

(NewProject) pkg> status
    Status `~/projects/julia/NewProject/Project.toml`
  [7806a523] DecisionTree v0.8.1

The folder “NewPackage” contains 2 files now:

$ tree .
.
├── Manifest.toml
└── Project.toml

0 directories, 2 files

Project.toml contains a list of all packages added:

$ less Project.toml                                                                                        

[deps]                                                                                                                                                    
DecisionTree = "7806a523-6efd-50cb-b5f6-3fa6f1930dbb"

Manifest.toml contains a list of all packages required/available in this project:

$ less Manifest.toml 
[[Base64]]                                                                                                                                                
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"                                                                                                             
                                                                                                                                                          
[[Compat]]                                                                                                                                                
deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"]                                   
git-tree-sha1 = "2d9e14d19bad3f9ad5cc5e4cffabc3cfa59de825"                                                                                                
uuid = "34da2185-b29b-5c13-b0c7-acf172513d20"                                                                                                             
version = "1.3.0"                                                                                                                                         
                                                                                                                                                          
[[Dates]]                                                                                                                                                 
deps = ["Printf"]
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"

[[DecisionTree]]
deps = ["DelimitedFiles", "Distributed", "LinearAlgebra", "Pkg", "Random", "ScikitLearnBase", "Statistics", "Test"]
git-tree-sha1 = "a0a1b9f70f9c57819aed52b2ce570de77bf0a6cf"
uuid = "7806a523-6efd-50cb-b5f6-3fa6f1930dbb"
version = "0.8.1"

[[DelimitedFiles]]
deps = ["Mmap"]
uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab"

[[Distributed]]
deps = ["LinearAlgebra", "Random", "Serialization", "Sockets"]
uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b"

[[InteractiveUtils]]
deps = ["LinearAlgebra", "Markdown"]
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"

[[LibGit2]]
uuid = "76f85450-5226-5b5a-8eaa-529ad045b433"

[[Libdl]]
uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb"

[[LinearAlgebra]]
deps = ["Libdl"]
uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

[[Logging]]
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"

[[Markdown]]
deps = ["Base64"]
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"

[[Mmap]]
uuid = "a63ad114-7e13-5084-954f-fe012c677804"

[[Pkg]]
deps = ["Dates", "LibGit2", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"]
uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"

[[Printf]]
deps = ["Unicode"]
uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7"

[[REPL]]
deps = ["InteractiveUtils", "Markdown", "Sockets"]
uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"

[[Random]]
deps = ["Serialization"]
uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

[[SHA]]
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"

[[ScikitLearnBase]]
deps = ["Compat", "LinearAlgebra", "Random", "Statistics", "Test"]
git-tree-sha1 = "0e27caac9a456b531193117c538d739d2d6e91c2"
uuid = "6e75b9c4-186b-50bd-896f-2d2496a4843e"
version = "0.4.1"

[[Serialization]]
uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b"

[[SharedArrays]]
deps = ["Distributed", "Mmap", "Random", "Serialization"]
uuid = "1a1011a3-84de-559e-8e89-a11a2f7dc383"

[[Sockets]]
uuid = "6462fe0b-24de-5631-8697-dd941f90decc"

[[SparseArrays]]
deps = ["LinearAlgebra", "Random"]
uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"

[[Statistics]]
deps = ["LinearAlgebra", "SparseArrays"]
uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"

[[Test]]
deps = ["Distributed", "InteractiveUtils", "Logging", "Random"]
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[[UUIDs]]
deps = ["Random"]
uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

[[Unicode]]
uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"