Book Image

Julia 1.0 Programming Cookbook

By : Bogumił Kamiński, Przemysław Szufel
Book Image

Julia 1.0 Programming Cookbook

By: Bogumił Kamiński, Przemysław Szufel

Overview of this book

Julia, with its dynamic nature and high-performance, provides comparatively minimal time for the development of computational models with easy-to-maintain computational code. This book will be your solution-based guide as it will take you through different programming aspects with Julia. Starting with the new features of Julia 1.0, each recipe addresses a specific problem, providing a solution and explaining how it works. You will work with the powerful Julia tools and data structures along with the most popular Julia packages. You will learn to create vectors, handle variables, and work with functions. You will be introduced to various recipes for numerical computing, distributed computing, and achieving high performance. You will see how to optimize data science programs with parallel computing and memory allocation. We will look into more advanced concepts such as metaprogramming and functional programming. Finally, you will learn how to tackle issues while working with databases and data processing, and will learn about on data science problems, data modeling, data analysis, data manipulation, parallel processing, and cloud computing with Julia. By the end of the book, you will have acquired the skills to work more effectively with your data
Table of Contents (18 chapters)
Title Page
Copyright and Credits
About Packt

Configuring Julia with Jupyter Notebook in Terminal-only cloud environments

In this recipe, we show how to configure Jupyter (both JupyterLab and Jupyter Notebook) for use in Terminal-only environments on a Linux platform (that is, environments that do not provide any graphical desktop interface). For these remote environments, running Jupyter Notebook is trickier. For illustrative purposes, we will use the AWS Cloud.

Getting ready

Before you start, you need to have a Linux machine with IJulia and either Jupyter Notebook or JupyterLab installed:


  1. Prepare a Linux machine (for example, an AWS EC2 instance) with Julia installed, and Jupyter Notebook or JupyterLab (you can follow the instructions in the previous recipes).

  2. Make sure that you can open an SSH connection to your Linux machine. If this is an instance of Linux on the AWS Cloud, you can follow the instructions given at particular, you need to know the server's address, login name (in the examples we use ubuntu, which is the default username on Ubuntu Linux), and have the private key file (in the examples, we name itkeyname.pem, and the user's password could be used instead of the key file).


Please note that for Windows 10, there is no default SSH client. Hence, this recipe has been tested with the SSH client included with Git for Windows tools, available at Once Git for Windows is installed, the SSH executable by default can be found at C:\Program Files\Git\usr\bin\ssh.exe.Please note that on *ux environments (for example, Linux, OS X) the key file, keyfile.pem, which is used for connection should be readable only to the local user. If you just downloaded it from AWS, you need to execute the$ chmod 400 keyfile.pem command before running the ssh command to open the SSH connection.


In the GitHub repository for this recipe, you will find the commands.txt file that contains the presented sequence of shell and Julia commands.

How to do it...

A general scenario for working with Jupyter Notebook/JupyterLab on a remote machine consists of the following three steps:

  1. Set up the SSH tunnel on port 8888
  2. Start JupyterLab on the remote machine
  3. Find the link in the launch log and copy it to the browser on the local machine

We discuss each step in detail and consider alternative configurations for Jupyter Notebook and JupyterLab:

  1. Connect to the Linux machine from your desktop computer (local machine). While opening the SSH connection, set up a tunnel on port 8888. In place of[enter_hostname_here], provide the appropriate hostname (for example, in the AWS Cloud, the hostname could look like this:
$ ssh -i path/to/keyfile.pem -L8888: ubuntu@[enter_hostname_here]


  1. Once the connection has been set up, run your Jupyter Notebook or JupyterLab on the remote machine. Execute the command shown (this assumes that the IJulia package is installed on your machine along with instructions from the previous recipes and you used the default setting for the Julia packages folder):
$ ~/.julia/packages/Conda/hsaaN/deps/usr/bin/jupyter lab

Please note that the Windows version of the preceding command is the following:

C:\> %userprofile%\.julia\packages\Conda\hsaaN\deps\usr\Scripts\jupyter-lab

You can also use either Jupyter Lab or Jupyter Notebook command versions (see the instructions from the previous recipe).


Please note that, depending on your Julia and Anaconda configuration, the executable jupyter file could be in a different location. On Linux environments, you can search for it with the $ find ~/ -name "jupyter" command. This assumes the search is run in your local home folder.

  1. Look for console output similar to this:
Copy/paste this URL into your browser when you connect for the first time,to login with a token:
  1. Paste the link marked with bold to your browser on your local machine (not the remote server).

If you have properly configured the SSH tunnel, you should see Jupyter Notebook/JupyterLab running on the remote server in the browser on the local machine. Please note that the environment will be available for only as long as the SSH connection is open. If you close the SSH connection, you will lose access to your Jupyter Notebook or JupyterLab.

How it works...

Using Jupyter Notebook via the internet requires setting up an SSH tunnel to the server. This is the option we present in this tutorial. Please note that on a local network, you can connect directly to the server without SSH tunneling.



In the preceding scenario, the command-line argument-L 8888: tells ssh to open a secure tunnel over SSH from your machine to port 8888 on the target machine in the cloud (as shown in the following diagram):

There's more...

Yet another option for running IJulia on a text-only Terminal remote machine is to use a detached mode for the Jupyter environment. However, in order to obtain access to Jupyter Notebook, a token key is required. Please see the following example: 

julia> usingIJulia

julia> notebook(detached=true)

julia> run(`$(IJulia.notebook_cmd[1]) notebook list`)
Currently running servers:

Now, you can simply copy and paste the preceding link into your web browser.

See also

More information on SSH tunneling can be found at