Book Image

Julia 1.0 Programming - Second Edition

By : Ivo Balbaert
Book Image

Julia 1.0 Programming - Second Edition

By: Ivo Balbaert

Overview of this book

The release of Julia 1.0 is now ready to change the technical world by combining the high productivity and ease of use of Python and R with the lightning-fast speed of C++. Julia 1.0 programming gives you a head start in tackling your numerical and data problems. You will begin by learning how to set up a running Julia platform, before exploring its various built-in types. With the help of practical examples, this book walks you through two important collection types: arrays and matrices. In addition to this, you will be taken through how type conversions and promotions work. In the course of the book, you will be introduced to the homo-iconicity and metaprogramming concepts in Julia. You will understand how Julia provides different ways to interact with an operating system, as well as other languages, and then you'll discover what macros are. Once you have grasped the basics, you’ll study what makes Julia suitable for numerical and scientific computing, and learn about the features provided by Julia. By the end of this book, you will also have learned how to run external programs. This book covers all you need to know about Julia in order to leverage its high speed and efficiency for your applications.
Table of Contents (17 chapters)
Title Page
Copyright and Credits
Packt Upsell
Contributors
Preface
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 it is delivered as a package or in an archive version. FreeBSD 64-bit is also supported.

 

 

You should use the current official stable release when doing serious professional work with Julia. At the time of writing, Julia has reached its version 1.0 production release. 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 OS

Keep in mind that your Windows OS must be version 7 or higher. Now, follow the steps shown here:

  1. Download the julia-n.m.p-win64.exe file into a temporary folder (n.m.p is the version number, such as 0.7.0 or 0.1.0; win32/win64 are the 32- and 64-bit versions, respectively; a release candidate file looks like julia-1.0.0-rc1-nnnnnnn-win64 (where nnnnnnn is a checksum number such as 0480f1b)).
  2. Double-click on the file (or right-click and select Run as Administrator if you want Julia installed for all users on the machine). Click OK on the security dialog message. Then, choose the installation directory (for example, forC:\julia, the default installation folder is: C:\Users\UserName\AppData\Local\Julia-n.m.p (where n.m.p is the version number)) and the setup program will extract the archive into the chosen folder, producing the following directory structure, and taking some 800 MB of disk space:

The Julia folder structure in Windows

  1. 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

  1. 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 window.
  2. More information on Julia's installation for the Windows OS can be found at https://github.com/JuliaLang/julia/blob/master/README.windows.md.

OS X

Installation for OS X is straightforward, and can be done 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.

Linux OS

Generic Linux binaries for x86 can be downloaded. This will get you a compressed tar.gz archive that will have a name similar to julia-1.0-linux-x86_64.tar.gz, for example, in your ~/Downloads directory in Ubuntu. Open up a Terminal window and navigate to the Downloads directory using cd Downloads. Move the tar.gz file to a directory of your choice, and then extract the tar.gz file using the tar -zxvf julia-1.0-linux-x86_64.tar.gzcommand. A directory with the extracted contents will be generated in the same parent directory as the compressed archive with a name similar to julia-n.m.p, where n.m.p is Julia's version number.

 

 

This is the directory from which Julia will be run; no further installation is needed. To run it, simply navigate to the julia-n.m.p\bin directory in your Terminal and type: ./julia.

If you want to be at the bleeding edge of development, you can download the nightly builds instead of the stable releases from https://julialang.org/downloads/nightlies.html. The nightly builds are generally less stable, but will contain the most recent features. They are available for Windows, Linux, and OS X.

The path to the Julia executable is contained in the environment variable, JULIA_BINDIR (for example, in our installation procedure, this was C:\Julia\bin on Windows).

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.

Building from source

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. The Julia source code can be found on GitHub at https://github.com/JuliaLang/julia.git. Compiling the source code 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).

Because of the diversity of platforms and the possible issues involved, we refer you to https://github.com/JuliaLang/julia, and in that, the Source Download and Compilation section.

JuliaPro

Another alternative is JuliaPro, which is available from https://juliacomputing.com/products/juliapro.html. This is an Anaconda-style Julia repository, which, at present, is only up to version 0.6.4. It does come with about 200+ verified ready-to-go packages, and is a very good way for beginners to start. JuliaPro version 1.0 will probably become available after some time.

 

 

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 program by starting it by running julia program.jl.