Book Image

Getting Started with Julia

By : Ivo Balbaert
Book Image

Getting Started with Julia

By: Ivo Balbaert

Overview of this book

Table of Contents (19 chapters)
Getting Started with Julia
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
The Rationale for Julia
Index

Installing Julia


The Julia platform in binary (that is, executable) form can be downloaded from http://julialang.org/downloads/. It exists for three major platforms (Windows, Linux, and OS X) in 32- and 64-bit format, and is delivered as a package or in an archive format. You should use the current official stable release when doing serious professional work with Julia (at the time of writing, this is Version 0.3). If you would like to investigate the latest developments, install the upcoming version (which is now Version 0.4). The previous link contains detailed and platform-specific instructions for the installation. We will not repeat these instructions here completely, but we will summarize some important points.

Windows version – usable from Windows XP SP2 onwards

You need to keep the following things in mind if you are using the Windows OS:

  1. As a prerequisite, you need the 7zip extractor program, so first download and install http://www.7-zip.org/download.html.

  2. Now, download the julia-n.m.p-win64.exe file to a temporary folder (n.m.p is the version number, such as 0.2.1 or 0.3.0; win32/win64 are respectively the 32- and 64-bit version; a release candidate file looks like julia-0.4.0-rc1-nnnnnnn-win64 (nnnnnnn is a checksum number such as 0480f1b).

  3. Double-click on the file (or right-click, and select Run as Administrator if you want Julia installed for all users on the machine). Clicking OK on the security dialog message, and then choosing the installation directory (for example, c:\julia) will extract the archive into the chosen folder, producing the following directory structure, and taking some 400 MB of disk space:

    The Julia folder structure in Windows

  4. A menu shortcut will be created which, when clicked, starts the Julia command-line version or Read Evaluate Print Loop (REPL), as shown in the following screenshot:

    The Julia REPL

  5. On Windows, if you have chosen C:\Julia as your installation directory, this is the C:\Julia\bin\julia.exe file. Add C:\Julia\bin to your PATH variable if you want the REPL to be available on any Command Prompt. The default installation folder on Windows is: C:\Users\UserName\AppData\Local\Julia-n.m.p (where n.m.p is the version number, such as 0.3.2).

  6. More information on Julia in the Windows OS can be found at https://github.com/JuliaLang/julia/blob/master/README.windows.md.

Ubuntu version

For Ubuntu systems (Version 12.04 or later), there is a Personal Package Archive (PPA) for Julia (can be found at https://launchpad.net/~staticfloat/+archive/ubuntu/juliareleases) that makes the installation painless. All you need to do to get the stable version is to issue the following commands in a terminal session:

sudo add-apt-repository ppa:staticfloat/juliareleases
sudo add-apt-repository ppa:staticfloat/julia-deps
sudo apt-get update
sudo apt-get install julia

If you want to be at the bleeding edge of development, you can download the nightly builds instead of the stable releases. The nightly builds are generally less stable, but will contain the most recent features. To do so, replace the first of the preceding commands with:

sudo add-apt-repository ppa:staticfloat/julianightlies

This way, you can always upgrade to a more recent version by issuing the following commands:

sudo apt-get update
sudo apt-get upgrade

The Julia executable lives in /usr/bin/julia (given by the JULIA_HOME variable or by the which julia command) and the standard library is installed in /usr/share/julia/base, with shared libraries in /usr/lib/x86_64-linux-gnu/Julia.

For other Linux versions, the best way to get Julia running is to build from source (refer to the next section).

OS X

Installation for OS X is straightforward—using the standard software installation tools for the platform. Add /Applications/Julia-n.m.app/Contents/Resources/julia/bin/Julia to make Julia available everywhere on your computer.

If you want code to be run whenever you start a Julia session, put it in /home/.juliarc.jl on Ubuntu, ~/.juliarc.jl on OS X, or c:\Users\username\.juliarc.jl on Windows. For instance, if this file contains the following code:

println("Greetings! 你好! 안녕하세요?")

Then, Julia starts up in its shell (or REPL as it is usually called) with the following text in the screenshot, which shows its character representation capabilities:

Using .juliarc.jl

Building from source

Perform the following steps to build Julia from source:

  1. Download the source code, rather than the binaries, if you intend to contribute to the development of Julia itself, or if no Julia binaries are provided for your operating system or particular computer architecture. Building from source is quite straightforward on Ubuntu, so we will outline the procedure here. The Julia source code can be found on GitHub at https://github.com/JuliaLang/julia.git.

  2. Compiling these will get you the latest Julia version, not the stable version (if you want the latter, download the binaries, and refer to the previous section).

  3. Make sure you have git installed; if not, issue the command:

    sudo apt-get -f install git
    
  4. Then, clone the Julia sources with the following command:

    git clone git://github.com/JuliaLang/julia.git
    

    This will download the Julia source code into a julia directory in the current folder.

  5. The Julia building process needs the GNU compilation tools g++, gfortran, and m4, so make sure that you have installed them with the following command:

    sudo apt-get install gfortran g++ m4
    
  6. Now go to the Julia folder and start the compilation process as follows:

    cd julia
    make
    
  7. After a successful build, Julia starts up with the ./julia command.

  8. Afterwards, if you want to download and compile the newest version, here are the commands to do this in the Julia source directory:

    git pull
    make clean
    make
    

For more information on how to build Julia on Windows, OS X, and other systems, refer to https://github.com/JuliaLang/julia/.

Tip

Using parallelization

If you want Julia to use n concurrent processes, compile the source with make -j n.

There are two ways of using Julia. As described in the previous section, we can use the Julia shell for interactive work. Alternatively, we can write programs in a text file, save them with a .jl extension, and let Julia execute the whole program sequentially.