How to automatically use packages at startup?

Is it possible to have the REPL automatically call using PackageName at startup? This seems very useful with 0.7 (using LinearAlgebra), etc.

I tried to find it the Julia docs, maybe the answer could be added to the FAQ under “Sessions and the REPL”.

There is ~/.juliarc.jl, which is executed by default for REPL and non-interactive sessions. You can disable it with the option --startup-file={yes|no} Load ~/.juliarc.jl.

It’s mentioned in a few places in the docs (easy to find if you know that it’s juliarc.jl` …), e.g.: https://docs.julialang.org/en/stable/manual/getting-started/#Getting-Started-1

3 Likes

Thanks! (I remembered there was a file, just couldn’t remember the name.)

This should be made very prominent in preparation for 0.7. (which is almost unusable without it, as if you forget using LinearAlgebra or using Random you have to start the REPL over again.)

3 Likes

What does rc stand for? juliarc seems like a particularly unmemorable name

1 Like

from http://www.catb.org/jargon/html/R/rc-file.html

[An rc file is a ] Script file containing startup instructions for an application program (or an entire operating system), usually a text file containing commands of the sort that might have been invoked manually once the system was running but are to be executed automatically each time the system starts up.

Its etymology is obscure (click the link for details), but it’s a unix convention (for example .bashrc).

I would say it is particularly memorable, looking at other examples:

.bashrc
.octaverc
.screenrc
.vimrc
.initrc

etc.

I may be missing something, but can’t you just load anything later if you need it? Why do you need to restart the REPL?

The namespace gets polluted, so you have to then do Random.rand to call rand

More evidence that we need a unix sans abbreviations. Programming should be easier than playing nethack.

I see, I think this was a blind spot for me given my workflow (doing almost everything in modules, with Revise.jl).

1.0 won’t be as bad as it’ll just error out with UndefVarError. It’s the deprecation message that makes this so painful.

  1. The abbreviation is standard on Unixes. This is the first thing an experienced user would look for.

  2. It is very well documented, both in Getting Started, and in the command line:

$ julia --help | grep juliarc
 --startup-file={yes|no}   Load ~/.juliarc.jl

FYI it’s been moved to ~/.julia/config/startup.jl

2 Likes

Hi. I’m trying to locate the startup.jl file but couldn’t find it. There is no config folder in ~/.julia/. I also try to find startup.jl with a fuzzy finder but couldn’t find it. I’m running Julia 1.5. Has this changed in the meantime (with the goal of loading script on startup)? Many thanks in advance

If it isn’t there, you can just create it.

2 Likes

Many thanks @kristoffer.carlsson ! that worked indeed!

As an experienced Linux user, I wouldn’t bat an eye at .julia/startup.jl either. And if I had to look for Julia’s config file I would write .jul and type tab anyway.

(And secretly think "I hope this is none of that fancy new stuff that puts config files in .config".)