In short, you can put your Julia source files wherever you want. ~/.julia/dev
just happens to be a common default.
If you like to access them from ~/src
, you could always do ln -s ~/.julia/dev ~/src/juliapkgs
on a *nix system.
As others have explained, Pkg.develop
and other tools such as PkgTemplates.jl
default to populating ~/.julia/dev
. You can change this default by setting the environment variable JULIA_PKG_DEVDIR
.
You mentioned executables in ~/bin
and libraries in ~/lib
. Julia workflows usually do not involve producing a lot of files that would be appropriate to put there. One exception may be using PakageCompiler.jl to produce apps, system images, or libraries.
As of Julia 1.9, Julia does produce native shared libraries (.so files) in ~/.julia/compiled/v1.9
but those are not really meant to be loaded outside of Julia.
Perhaps the most common workflow that may involve placing files in ~/bin
are executable scripts. I’ll show a minimal example of an “executable” project package.
$ tree -p src/HelloWorld.jl/
[drwxrwxr-x] src/HelloWorld.jl/
├── [drwxrwxr-x] bin
│ └── [-rwxrwxr-x] helloworld.jl
├── [-rw-rw-r--] Project.toml
└── [drwxrwxr-x] src
└── [-rw-rw-r--] HelloWorld.jl
2 directories, 3 files
$ cat src/HelloWorld.jl/src/HelloWorld.jl
module HelloWorld
__init__() = println("Hello World")
end
$ cat src/HelloWorld.jl/bin/helloworld.jl
#!/bin/env julia
using Pkg
if length(ARGS) > 0 && ARGS[1] == "-q"
io = devnull
else
io = stdout
end
Pkg.activate(
@__FILE__() |>
x->(islink(x) ? readlink(x) : x) |>
dirname |>
dirname
; io
)
using HelloWorld
From Julia, one may load this package in the following way.
$ julia --project=src/HelloWorld.jl -e "using HelloWorld"
Hello World
If we just want a generic executable script, then we can use the helloworld.jl
file.
$ src/HelloWorld.jl/bin/helloworld.jl
Activating project at `~/src/HelloWorld.jl`
Hello World
Now you may want this always on your shell’s path. Assuming that ~/bin
is on your shell’s path, you could then do the following.
$ ln -s ~/src/HelloWorld.jl/bin/helloworld.jl ~/bin
$ helloworld.jl
Activating project at `~/src/HelloWorld.jl`
Hello World
Additionally, I can also load this package into another Julia environment. Below I use Pkg.develop
to incorporate it into a temporary Julia environment.
$ julia -e 'using Pkg; Pkg.activate(; temp=true); Pkg.develop(path="$(ENV["HOME"])/src/HelloWorld.jl"); using HelloWorld'
Activating new project at `/tmp/jl_XxWuFq`
Resolving package versions...
Updating `/tmp/jl_XxWuFq/Project.toml`
[ba1a46c8] + HelloWorld v0.0.0 `~/src/HelloWorld.jl`
Updating `/tmp/jl_XxWuFq/Manifest.toml`
[ba1a46c8] + HelloWorld v0.0.0 `~/src/HelloWorld.jl`
Hello World
Part of the reason I have the code arranged as a package is the because is the basic cacheable compilation unit in Julia.
$ ls ~/.julia/compiled/v1.9/HelloWorld
QoJsw_rFRaA.ji QoJsw_rFRaA.so
I hope that helps.