Creating decent julia's environment variable paths on UNIX-like system using XDG specs to avoid ~/.julia

As a brand-new julia programmer, I am striving to tidy up my $HOME dir in order to avoid bloating it up with a tons of dotfiles, and at same time, define sane paths to julia using XDG Base Directory Specification. The steps defined in the Official instruction will generate the dir ~/.julia, which is rather unpleasant… So I am trying a way out to this problem following sane UNIX path definitions.

After reading the julia’s environment variables and some discussions about it, I bite the bullet and tried to organize it in the following way (probably not the most optimized, so help me):

Firstly, I decided to put the extracted julia/ directory inside $XDG_DATA_HOME as it is user-specific data files, right? So a ran

mv julia-1.7.2 $XDG_DATA_HOME

The julia’s documentation ask me to define the path to julia’s bin/ dir as an env variable $JULIA_BINDIR. To do so, I defined in ~/.profile:

# The absolute path of the directory containing the Julia executable -> ~/.local/share/julia-1.7.2/bin
export JULIA_BINDIR="$XDG_DATA_HOME/julia-1.7.2/bin"

The documentation also ask me to put the julia bin in the $PATH. Hence, I symlink

ln -s $XDG_DATA_HOME/julia-1.7.2/bin/julia ~/.local/bin/julia

because User-specific executable files shall be stored in $HOME/.local/bin. This resolve the problem of putting the julia into the $PATH as long as ~/.local/bin is in it.

I would also like to put the data and config file of julia into $XDG_DATA_HOME and $XDG_CONFIG_HOME, respectively, which matches with the XDG Base Directory Specifications. So I added in my .profile the following env. variables:

# relative julia's data directory -> $JULIA_BINDIR/$DATAROOTDIR/julia/base -> ~/.local/share/julia/base
export DATAROOTDIR="../.."
# relative julia's config files -> $JULIA_BINDIR/$SYSCONFDIR/julia/startup.jl -> ~/.config/julia/startup.jl
export SYSCONFDIR="../../../../.config"

Both $DATAROOTDIR and $SYSCONFDIR are relative paths to the data directory and configuration file directory, respectively. With these environment variables, I am pointing the data dir at $XDG_DATA_HOME/julia and the config dir at $XDG_CONFIG_HOME/julia. To have such directories in theses paths, I symlinked again

ln -s $XDG_DATA_HOME/julia-1.7.2/share/julia $XDG_DATA_HOME/julia
ln -s $XDG_DATA_HOME/julia-1.7.2/etc/julia $XDG_CONFIG_HOME/julia

Moreover, I put the Julia history into $XDG_STATE_HOME as that path should be used to store “logs, history, recently used files”, but I barely see UNIX users using this dir. I just added to .profile the following line


At moment, when I open up julia on terminal in REPL mode, my computer does not generate ~/.julia/ (thanks God), but I bet my way have flaws, so any contribution is welcome.

Thanks in advance.

I agree using XDG would be nice, but there has been a long discussion with good points made against its use here: Store settings and packages in XDG directories instead of ~/.julia · Issue #4630 · JuliaLang/julia · GitHub

I think the most productive way to engage this conversation would be at that github issue. I view it as something that does not have much of a chance of happening (a bit of a tragedy of the commons).

EDIT: To be fair, your goal is slightly different. It is not about making the default be XDG, but rather about making it possible to configure the use of XDG. That is probably something you would have much more success with.

The status of that issue is that there is willingness to support opting into XDG. There’s even a plan for where the different kinds of data should go. The only thing lacking is for someone to actually implement the plan and make a pull request. The overlap between people who want Julia to support XDG and people who are willing/able to implement that support appears to be the empty set.

1 Like