# 环境变量

Julia 可以配置许多环境变量，一种常见的方式是直接配置操作系统环境变量，另一种更便携的方式是在 Julia 中配置。假设你要将环境变量 JULIA_EDITOR 设置为 vim，可以直接在 REPL 中输入 ENV["JULIA_EDITOR"] = "vim"（请根据具体情况对此进行修改），也可以将其添加到用户主目录中的配置文件 ~/.julia/config/startup.jl，这样做会使其永久生效。环境变量的当前值是通过执行 ENV["JULIA_EDITOR"] 来确定的。

The environment variables that Julia uses generally start with JULIA. If InteractiveUtils.versioninfo is called with the keyword verbose=true, then the output will list any defined environment variables relevant for Julia, including those which include JULIA in their names.

Note

Some variables, such as JULIA_NUM_THREADS and JULIA_PROJECT, need to be set before Julia starts, therefore adding these to ~/.julia/config/startup.jl is too late in the startup process. In Bash, environment variables can either be set manually by running, e.g., export JULIA_NUM_THREADS=4 before starting Julia, or by adding the same command to ~/.bashrc or ~/.bash_profile to set the variable each time Bash is started.

## 文件位置

### JULIA_BINDIR

$JULIA_BINDIR/julia-debug 全局变量 Base.DATAROOTDIR 是一个从 Sys.BINDIR 到 Julia 数据目录的相对路径。 $JULIA_BINDIR/$DATAROOTDIR/julia/base 上述路径是 Julia 最初搜索源文件的路径（通过 Base.find_source_file()）。 同样，全局变量 Base.SYSCONFDIR 是一个到配置文件目录的相对路径。在默认情况下，Julia 会在下列文件中搜索 startup.jl 文件（通过 Base.load_julia_startup() $JULIA_BINDIR/$SYSCONFDIR/julia/startup.jl$JULIA_BINDIR/../etc/julia/startup.jl

/share/julia/base

/etc/julia/startup.jl

### JULIA_PROJECT

A directory path that indicates which project should be the initial active project. Setting this environment variable has the same effect as specifying the --project start-up option, but --project has higher precedence. If the variable is set to @. then Julia tries to find a project directory that contains Project.toml or JuliaProject.toml file from the current directory and its parents. See also the chapter on Code Loading.

Note

JULIA_PROJECT must be defined before starting julia; defining it in startup.jl is too late in the startup process.

### JULIA_LOAD_PATH

The JULIA_LOAD_PATH environment variable is used to populate the global Julia LOAD_PATH variable, which determines which packages can be loaded via import and using (see Code Loading).

Unlike the shell PATH variable, empty entries in JULIA_LOAD_PATH are expanded to the default value of LOAD_PATH, ["@", "@v#.#", "@stdlib"] when populating LOAD_PATH. This allows easy appending, prepending, etc. of the load path value in shell scripts regardless of whether JULIA_LOAD_PATH is already set or not. For example, to prepend the directory /foo/bar to LOAD_PATH just do

export JULIA_LOAD_PATH="/foo/bar:$JULIA_LOAD_PATH" If the JULIA_LOAD_PATH environment variable is already set, its old value will be prepended with /foo/bar. On the other hand, if JULIA_LOAD_PATH is not set, then it will be set to /foo/bar: which will expand to a LOAD_PATH value of ["/foo/bar", "@", "@v#.#", "@stdlib"]. If JULIA_LOAD_PATH is set to the empty string, it expands to an empty LOAD_PATH array. In other words, the empty string is interpreted as a zero-element array, not a one-element array of the empty string. This behavior was chosen so that it would be possible to set an empty load path via the environment variable. If you want the default load path, either unset the environment variable or if it must have a value, set it to the string :. ### JULIA_DEPOT_PATH The JULIA_DEPOT_PATH environment variable is used to populate the global Julia DEPOT_PATH variable, which controls where the package manager, as well as Julia's code loading mechanisms, look for package registries, installed packages, named environments, repo clones, cached compiled package images, configuration files, and the default location of the REPL's history file. Unlike the shell PATH variable but similar to JULIA_LOAD_PATH, empty entries in JULIA_DEPOT_PATH are expanded to the default value of DEPOT_PATH. This allows easy appending, prepending, etc. of the depot path value in shell scripts regardless of whether JULIA_DEPOT_PATH is already set or not. For example, to prepend the directory /foo/bar to DEPOT_PATH just do export JULIA_DEPOT_PATH="/foo/bar:$JULIA_DEPOT_PATH"

If the JULIA_DEPOT_PATH environment variable is already set, its old value will be prepended with /foo/bar. On the other hand, if JULIA_DEPOT_PATH is not set, then it will be set to /foo/bar: which will have the effect of prepending /foo/bar to the default depot path. If JULIA_DEPOT_PATH is set to the empty string, it expands to an empty DEPOT_PATH array. In other words, the empty string is interpreted as a zero-element array, not a one-element array of the empty string. This behavior was chosen so that it would be possible to set an empty depot path via the environment variable. If you want the default depot path, either unset the environment variable or if it must have a value, set it to the string :.

### JULIA_HISTORY

REPL 历史文件中 REPL.find_hist_file() 的绝对路径。如果没有设置 $JULIA_HISTORY，那么 REPL.find_hist_file() 默认为 $(DEPOT_PATH[1])/logs/repl_history.jl

## 外部应用

### JULIA_SHELL

Julia 用来执行外部命令的 shell 的绝对路径（通过 Base.repl_cmd()）。默认为环境变量 $SHELL，如果 $SHELL 未设置，则为 /bin/sh

Note

### JULIA_EDITOR

InteractiveUtils.editor() 的返回值–编辑器，例如，InteractiveUtils.edit，会启动偏好编辑器，比如 vim

## REPL 格式化输出

### JULIA_ERROR_COLOR

Base.error_color()（默认值：亮红，"\033[91m"），errors 在终端中的格式。

### JULIA_WARN_COLOR

Base.warn_color()（默认值：黄，"\033[93m"），warnings 在终端中的格式。

### JULIA_INFO_COLOR

Base.info_color()（默认值：青，"\033[36m"），info 在终端中的格式。

### JULIA_INPUT_COLOR

Base.input_color()（默认值：标准，"\033[0m"），在终端中，输入应有的格式。

### JULIA_ANSWER_COLOR

Base.answer_color()（默认值：标准，"\033[0m"），在终端中，输出应有的格式。

### JULIA_STACKFRAME_LINEINFO_COLOR

Base.stackframe_lineinfo_color()（默认值：粗体，"\033[1m"），栈跟踪时行信息在终端中的格式。

### JULIA_STACKFRAME_FUNCTION_COLOR

Base.stackframe_function_color()（默认值：粗体，"\033[1m"），栈跟踪期间函数调用在终端中的形式。

## 调试和性能分析

### JULIA_DEBUG

Enable debug logging for a file or module, see Logging for more information.

### JULIA_GC_ALLOC_POOL, JULIA_GC_ALLOC_OTHER, JULIA_GC_ALLOC_PRINT

• 如果是第 n 次调用 jl_gc_pool_alloc()，并且 n 属于 $JULIA_GC_ALLOC_POOL 代表的算术序列， 那么垃圾回收是强制的。 • 如果是第 n 次调用 maybe_collect()，并且 n 属于 $JULIA_GC_ALLOC_OTHER 代表的算术序列，那么垃圾 回收是强制的。
• 如果是第 n 次调用 jl_gc_alloc()，并且 n 属于 \$JULIA_GC_ALLOC_PRINT 代表的算术序列，那么 调用 jl_gc_pool_alloc()maybe_collect() 的次数会 被打印。

Note

Note

Note

### ENABLE_JITPROFILING

Note

• 英特尔的 VTune™ Amplifier（在构建配置中将 USE_INTEL_JITEVENTS 设置为 1），或
• OProfile（在构建配置中将 USE_OPROFILE_JITEVENTS 设置为 1）。