I want to change the Package directory in Julia. The default is
"~/.julia/v0.4"
I want to move it to /opt/julia/v0.4/
. Ideally I want to move the packages that are already installed in ~/.julia/v0.4
to the new location. But if that is not possible I can reinstall them.
What do I have to do?
The command to change working directory is cd(dir::AbstractString=homedir()).
The list of registered Julia packages can be found at http://pkg.julialang.org. All package manager commands are found in the Pkg module, included in Julia's Base install.
Enter the Pkg REPL by pressing ] from the Julia REPL. To get back to the Julia REPL, press backspace or ^C.
one can change julia's package directory by following these steps:
export JULIA_PKGDIR=/your/directory
in shell(or manually add a new environment variable JULIA_PKGDIR
on windows)Pkg.init()
in julia to initialize a new package systemREQUIRE
from old directory to the new one Pkg.resolve()
in juliaThe "Package directory" in the new package manager is called DEPOT_PATH
, it can be changed by adding an environment variable JULIA_DEPOT_PATH
:
JULIA_DEPOT_PATH=./test julia julia> DEPOT_PATH 1-element Array{String,1}: "./test" (v0.7) pkg> add JSON2 Cloning default registries into /Users/gnimuc/test/registries
With the new package manager, we are able to create isolated projects in any directory we want instead of having a single giant package directory. Every project contains a Project.toml
and a Manifest.toml
if it has some dependencies. These two files record and keep tracking the environment of the project.
The following info might be obsoleted. I highly recommend to use PkgTemplates.jl for generating projects in Julia-v1.0+.
We can generate a new project in any folder, but we must cd
to the project folder to using
the project. The (v0.7)
below shows we're still in the default environment, so we cannot use the newly generated project:
(v0.7) pkg> generate ./MyNewProject Generating project MyNewProject: ./MyNewProject/Project.toml ./MyNewProject/src/MyNewProject.jl julia> using MyNewProject ERROR: ArgumentError: Module MyNewProject not found in current path. Run `Pkg.add("MyNewProject")` to install the MyNewProject package. Stacktrace: [1] require(::Module, ::Symbol) at ./loading.jl:868
If we cd
to the project folder and activate
the environment, then we can using
our new project without any problems:
shell> cd MyNewProject/ /Users/gnimuc/MyNewProject (v0.7) pkg> activate . (MyNewProject) pkg> julia> using MyNewProject
I think that's the big difference between the new package manager and the old one. In short, we need to explicitly activate
our unregistered project/package.
According to the doc, we can add an unregistered package/project via add
command:
(HelloWorld) pkg> add https://github.com/fredrikekre/ImportMacros.jl
This command adds the target package as a dependency of our current project. In this example, we added ImportMacros
in HelloWorld
's Manifest.toml
. What if we just use it as a top-level project? To add it to the default environment (v0.7)
? no, we don't need to. The answer is we can directly download the code, cd
to the folder and run instantiate
in the pkg mode:
shell> git clone https://github.com/Gnimuc/GLTF.jl GLTF Cloning into 'GLTF'... remote: Counting objects: 286, done. remote: Compressing objects: 100% (56/56), done. remote: Total 286 (delta 73), reused 103 (delta 59), pack-reused 167 Receiving objects: 100% (286/286), 62.16 KiB | 46.00 KiB/s, done. Resolving deltas: 100% (135/135), done. shell> cd GLTF pkg> activate . (GLTF) pkg> instantiate Updating registry at `~/.julia/registries/General` Updating git-repo `https://github.com/JuliaRegistries/General.git`
The new package manager is great! We neither need "include
before using
" nor make everything as a package just for using
it. We have full-featured "Project" now!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With