Introducing Julia/Getting started

From Wikibooks, open books for an open world
Jump to navigation Jump to search
« Introducing Julia
Getting Started
Contents The REPL

Getting started[edit]

To install Julia on your computer, visit and follow instructions.

You can use Julia online, in a browser. JuliaBox provides online IJulia notebooks, which let you run Julia on a remote machine, using Jupyter (formerly IPython) interactive notebooks. Jupyter is the interactive notebook technology that lets you run code in Julia, Python, and R in a browser window. You'll need to log in using your Google or GitHub identities.

Alternatively, you can install a local version of IJulia by installing IJulia.

On Mac OS X[edit]

On a Mac, you download the Julia DMG, double-click to open it, and drag the icon to the Applications folder. To run Julia, you can double-click the icon of the Julia package in the /Applications folder. This opens the terminal application, and starts a new window. This is the REPL, introduced in the next section:

$ julia
   _       _ _(_)_     |  A fresh approach to technical computing
  (_)     | (_) (_)    |  Documentation:
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 0.7.0-alpha.5 (2018-05-31 21:00 UTC)
 _/ |\__'_|_|_|\__'_|  |  Commit 62fa2aa3bc (8 days old master)
|__/                   |  x86_64-apple-darwin14.5.0


Alternatively, you can type, in a terminal, something like this:

$ /Applications/

— here you’re specifying the path name of the Julia binary executable that lives inside the Julia application bundle. The exact version name might be different — check it using the command:

$ ls /Applications/Julia*/Contents/Resources/julia/bin/julia

Running directly from terminal[edit]

Typically, Julia is installed in /Applications, which isn't included in your PATH, and so the shell won't find it when you type julia on the command line.

But there are clever things you can do with paths and profiles, so that you can log in to a terminal and type julia with immediate success.

For example, after you find out the location of the Julia binary executable file (see above), you can define the following alias:

alias julia="/Applications/"

Obviously this will have to be updated every time the version number changes.

As an alternative, you could add the /Applications/Julia... path to the PATH variable:

export PATH

A different approach is to create a link to the executable and put it into the /usr/local/bin directory (which should already be in your path), so that typing julia is the exact equivalent of typing /Applications/Julia/.../julia. This command does that:

ln -fs "/Applications/" /usr/local/bin/julia

Whichever method you choose, you can add the relevant command to your ~/.bash_profile file to run every time you create a new shell.

You can use the 'shebang' line at the top of a text file ('script') so that the shell can find Julia and execute the file:

#!/usr/bin/env julia

This also works in a lot of text editors, so that you can choose Run to run the file. This works if the editor reads the user's environment variables before running the file. (But not all do!)

Running a Julia program[edit]

If you have a text file containing Julia code, you can run it from the command-line:

$ julia hello-world.jl

or from within the Julia REPL:

$ julia
julia> include("hello-world.jl")

If the first line specifies a Julia interpreter:



#!/usr/bin/env julia

you can run the file like this:

$ ./hello-world.jl

Running a script with Julia[edit]

If you want to write Julia code in an editor and run it, in true scripting-language fashion, you can. At the top of the script file, add a line like the following:


where the pathname points to the right place on your system, somewhere inside the relevant Julia application bundle, or:

#!/usr/bin/env julia

This is the shebang line.

Now you can run the script from inside the editor in the same way that you'd run a Perl script.

On Windows[edit]

On a Windows machine, you download the Julia Self-Extracting Archive (.exe) 32-bit or 64-bit. Double-click to start the installation process.

By default, it will install to your AppData folder. You may keep the default or choose your own directory (eg. C:\Julia).

After the installation has finished, you should create a System Environment variable called JULIA_HOME and set its value to the \bin directory under the folder where you installed Julia.

It is important to point JULIA_HOME to the /bin directory instead of the JULIA directory.

Then you can append ;%JULIA_HOME% to your PATH System Environment variable, so you can run scripts from any directory. Make sure that the registry key HKEY_CURRENT_USER\Environment\Path is of type REG_EXPAND_SZ, so %JULIA_HOME% gets expanded properly.

On FreeBSD[edit]

To install Julia on FreeBSD (including TrueOS) or DragonFly BSD you can use either a binary package or using the ports system.

Installing from package[edit]

Installing the Julia package is straight forward. Open up a terminal and type:

$ pkg install julia

To remove the package again you can use:

$ pkg remove julia

Installing from ports[edit]

If you have the ports collection installed on your system (you can do so using running the command portsnap auto) the following is the canonical way to compile and install Julia onto your system:

$ cd /usr/ports/lang/julia/ && make install clean

On Linux[edit]

Installing from package[edit]

This is the easiest way to install Julia if you're using Linux distributions based on RedHat, Fedora, Debian or Ubuntu. To install, download the respective package from the website (or JuliaPro), and install using your favorite way (double-clicking on the package file usually works). After doing this, Julia will be availabe from command line. On a terminal you can do:

$ julia
   _       _ _(_)_     |  A fresh approach to technical computing
  (_)     | (_) (_)    |  Documentation:
   _ _   _| |_  __ _   |  Type "help()" to list help topics
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version xxxxxxxxxxx
 _/ |\__'_|_|_|\__'_|  |  Commit xxxxxx
|__/                   |  


Arch Linux[edit]

On Arch Linux, Julia is available from community repository, and can be installed running:

$ sudo pacman -S julia

To remove Julia package and it's dependencies (if not used by any other software on your system), you can run:

$ sudo pacman -Rsn julia


On Fedora distributions, Julia is available from the updates repository (a default repository) and can be installed running:

$ sudo dnf install julia

To remove Julia package and it's dependencies (again, if not used by other software on your system), you can run:

$ sudo dnf remove julia

Please note, this applies only to Fedora, downstream distributions such as RHEL or CentOS must check their own repositories to see if Julia is available.

Using Binaries[edit]

You can use Julia direct from the binaries, without installing it on your machine. This is usefull if you have old Linux distributions or if you don't have administrator's access to the machine. Just download the binaries from the website, extract to a directory. While in this directory, enter the bin folder and run:

$ ./julia

If the program doesn't have permission to run, use the following command to give this permission:

$ chmod +x julia 

In principle, this method could be used on any Linux distribution.

Running a script with Julia[edit]

To tell your operating system that it should run the script using Julia, you can use what is called the shebang syntax. To do this, just use the following line on the very top of your script:

#!/usr/bin/env julia

With this as the first line of the script, the OS will search for "julia" on the path, and use it to run the script.