There are four methods you can use to parameterize the booting of Julia:
- By setting startup switches
- By passing a startup file
- By defining the ~/.julia/config/startup.jl file
- By setting environment variables
The general structure of running Julia from the command line is this:
$ julia [switches] -- [programfile] [args...]
The simplest way to control Julia startup is to pass switches to it. You can get the full list of switches by running the following in the console:
$ julia --help
In the previous examples, we have used three switches:Â -i, -e, and --banner=no.
The first of these switches (-i) keeps Julia in interactive mode after executing the commands. If we did not use the -i switch then Julia would terminate immediately after finishing the passed commands.
You can pass Julia a file to execute directly or a command to run following the -e switch. The latter option is useful if you want to execute a short expression. However, if we want to start some commands repeatedly every time Julia starts, we can save them in the ~/.julia/config/startup.jl file. It will be run every time Julia starts unless you set the --startup-file=no command line switch.
In the preceding path, ~ is your home directory. Under Linux, this should simply work. Under Windows, you can check its location by running homedir() in the Julia command line (typically, it will be the C:\Users\[username] directory).
What are some useful things to put into ~/.julia/config/startup.jl?
In the recipe, we put the using Random statement in ~/.julia/config/startup.jl to load the Random package by default, since we routinely need it in our daily work. The second command, ENV["JULIA_EDITOR"]="vim", specifies a default editor used by Julia. Use of the editor in Julia is explained in the Useful options for interaction with Julia recipe.