# Building Julia (Detailed)

If you are behind a firewall, you may need to use the https protocol instead of the git protocol:

git config --global url."https://".insteadOf git://

Be sure to also configure your system to use the appropriate proxy settings, e.g. by setting the https_proxy and http_proxy variables.

## Building Julia

When compiled the first time, the build will automatically download pre-built external dependencies. If you prefer to build all the dependencies on your own, or are building on a system that cannot access the network during the build process, add the following in Make.user:

USE_BINARYBUILDER=0

Building Julia requires 5GiB if building all dependencies and approximately 4GiB of virtual memory.

To perform a parallel build, use make -j N and supply the maximum number of concurrent processes. If the defaults in the build do not work for you, and you need to set specific make parameters, you can save them in Make.user, and place the file in the root of your Julia source. The build will automatically check for the existence of Make.user and use it if it exists.

You can create out-of-tree builds of Julia by specifying make O=<build-directory> configure on the command line. This will create a directory mirror, with all of the necessary Makefiles to build Julia, in the specified directory. These builds will share the source files in Julia and deps/srccache. Each out-of-tree build directory can have its own Make.user file to override the global Make.user file in the top-level folder.

If everything works correctly, you will see a Julia banner and an interactive prompt into which you can enter expressions for evaluation. (Errors related to libraries might be caused by old, incompatible libraries sitting around in your PATH. In this case, try moving the julia directory earlier in the PATH). Note that most of the instructions above apply to unix systems.

To run julia from anywhere you can:

• add an alias (in bash: echo "alias julia='/path/to/install/folder/bin/julia'" >> ~/.bashrc && source ~/.bashrc), or

• add a soft link to the julia executable in the julia directory to /usr/local/bin (or any suitable directory already in your path), or

• add the julia directory to your executable path for this shell session (in bash: export PATH="$(pwd):$PATH" ; in csh or tcsh:

set path= ( $path$cwd ) ), or

• add the julia directory to your executable path permanently (e.g. in .bash_profile), or

• write prefix=/path/to/install/folder into Make.user and then run make install. If there is a version of Julia already installed in this folder, you should delete it before running make install.

Now you should be able to run Julia like this:

julia

If you are building a Julia package for distribution on Linux, macOS, or Windows, take a look at the detailed notes in distributing.md.

## Updating an existing source tree

If you have previously downloaded julia using git clone, you can update the existing source tree using git pull rather than starting anew:

cd julia
git pull && make

Assuming that you had made no changes to the source tree that will conflict with upstream updates, these commands will trigger a build to update to the latest version.

## General troubleshooting

1. Over time, the base library may accumulate enough changes such that the bootstrapping process in building the system image will fail. If this happens, the build may fail with an error like

 *** This error is usually fixed by running 'make clean'. If the error persists, try 'make cleanall' ***

As described, running make clean && make is usually sufficient. Occasionally, the stronger cleanup done by make cleanall is needed.

2. New versions of external dependencies may be introduced which may occasionally cause conflicts with existing builds of older versions.

a. Special make targets exist to help wipe the existing build of a dependency. For example, make -C deps clean-llvm will clean out the existing build of llvm so that llvm will be rebuilt from the downloaded source distribution the next time make is called. make -C deps distclean-llvm is a stronger wipe which will also delete the downloaded source distribution, ensuring that a fresh copy of the source distribution will be downloaded and that any new patches will be applied the next time make is called.

b. To delete existing binaries of julia and all its dependencies, delete the ./usr directory in the source tree.

3. If you've updated macOS recently, be sure to run xcode-select --install to update the command line tools. Otherwise, you could run into errors for missing headers and libraries, such as ld: library not found for -lcrt1.10.6.o.

4. If you've moved the source directory, you might get errors such as CMake Error: The current CMakeCache.txt directory ... is different than the directory ... where CMakeCache.txt was created., in which case you may delete the offending dependency under deps

5. In extreme cases, you may wish to reset the source tree to a pristine state. The following git commands may be helpful:

 git reset --hard #Forcibly remove any changes to any files under version control
git clean -x -f -d #Forcibly remove any file or directory not under version control

To avoid losing work, make sure you know what these commands do before you run them. git will not be able to undo these changes!

## Platform-Specific Notes

Notes for various operating systems:

Notes for various architectures:

## Required Build Tools and External Libraries

Building Julia requires that the following software be installed:

• [GNU make] — building dependencies.
• [gcc & g++][gcc] (>= 5.1) or [Clang][clang] (>= 3.5, >= 6.0 for Apple Clang) — compiling and linking C, C++.
• [libatomic][gcc] — provided by [gcc] and needed to support atomic operations.
• [python] (>=2.7) — needed to build LLVM.
• [gfortran] — compiling and linking Fortran libraries.
• [perl] — preprocessing of header files of libraries.
• [wget], [curl], or [fetch] (FreeBSD) — to automatically download external libraries.
• [m4] — needed to build GMP.
• [awk] — helper tool for Makefiles.
• [patch] — for modifying source code.
• [cmake] (>= 3.4.3) — needed to build libgit2.
• [pkg-config] — needed to build libgit2 correctly, especially for proxy support.
• [powershell] (>= 3.0) — necessary only on Windows.
• [which] — needed for checking build dependencies.

On Debian-based distributions (e.g. Ubuntu), you can easily install them with apt-get:

sudo apt-get install build-essential libatomic1 python gfortran perl wget m4 cmake pkg-config curl

$docker run --platform i386 -i -t i386/ubuntu /bin/bash At this point you should be in a 32-bit machine console (note that uname reports the host architecture, so will still say 64-bit, but this will not affect the Julia build). You can add packages and compile code; when you exit, all the changes will be lost, so be sure to finish your analysis in a single session or set up a copy/pastable script you can use to set up your environment. From this point, you should # apt update (Note that sudo isn't installed, but neither is it necessary since you are running as root, so you can omit sudo from all commands.) Then add all the build dependencies, a console-based editor of your choice, git, and anything else you'll need (e.g., gdb, rr, etc). Pick a directory to work in and git clone Julia, check out the branch you wish to debug, and build Julia as usual. ## Update the version number of a dependency There are two types of builds 1. Build everything (deps/ and src/) from source code. (Add USE_BINARYBUILDER=0 to Make.user, see Building Julia) 2. Build from source (src/) with pre-compiled dependencies (default) When you want to update the version number of a dependency in deps/, you may want to use the following checklist: ### Check list Version numbers: - [ ] deps/$(libname).version: LIBNAME_VER, LIBNAME_BRANCH, LIBNAME_SHA1 and LIBNAME_JLL_VER
- [ ] stdlib/$(LIBNAME_JLL_NAME)_jll/Project.toml: version Checksum: - [ ] deps/checksums/$(libname)
- [ ] deps/checksums/$(LIBNAME_JLL_NAME)-*/: md5 and sha512 Patches: - [ ] deps/$(libname).mk
- [ ] deps/patches/\$(libname)-*.patch

Note:

• For specific dependencies, some items in the checklist may not exist.
• For checksum file, it may be a single file without a suffix, or a folder containing two files.

### Example: OpenLibm

1. Update Version numbers in deps/openlibm.version
• OPENLIBM_VER := 0.X.Y
• OPENLIBM_BRANCH = v0.X.Y
• OPENLIBM_SHA1 = new-sha1-hash
2. Update Version number in stdlib/OpenLibm_jll/Project.toml
• version = "0.X.Y+0"
3. Update checksums in deps/checksums/openlibm
• make -f contrib/refresh_checksums.mk openlibm
4. Check if the patch files deps/patches/openlibm-*.patch exist
• if patches don't exist, skip.
• if patches exist, check if they have been merged into the new version and need to be removed. When deleting a patch, remember to modify the corresponding Makefile file (deps/openlibm.mk).