Julia is high performance dynamically-typed programming language. It is build especially for scientific and numerical computing. Jupyter notebook can run Julia so it becomes a reliable medium to code in Julia on Google cloud platform (GCP). GCP is a suite of public cloud computing services provided by Google, it helps us to compute, store or develop our programs or applications on Google hardware.
Sometimes it becomes difficult to compute things in our local computer. For such situations, GCP becomes a great option. Their are a lot of articles available for other programming languages to setup GCP but for Julia their is lack of articles which become makes hard for Julia users to setup Julia in GCP. I faced the same issue and hence wanted to help people facing similar problem.
In this blog, I will show to setup things on Ubuntu 16.04 OS, but the for other systems the procedure will be same.
- Create a GCP VM instance.
- Set external IP address static for created instance.
- Create a firewall rule with a tcp port.
- Open Secure Shell (SSH).
- Install Jupyter notebook and configure it.
- Install Julia and add IJulia library.
Create a GCP VM instance:
Firstly, you should have a Google account to create instance. After logging into the account, go to Compute Engine >> VM instances >> Create Instance
Set External IP address static:
In order to use Jupyter notebook on your local machine we need to set external IP address to that instance to static. To do so, go to Networking >> VPC networks >> External IP addresses. There change IP address from Ephemeral to Static for current instance.
Creating firewall rule:
We need to create a firewall rule to set a tcp port to access Jupyter notebook. Again in VPC networks go to Firewall rules then create a firewall rule with TCP port of your choice (say 5000).
Open Secure shell:
SSH can be opened direct by clicking on on SSH button in VM instances or can also be opened in third party software like PuTTY, you can also use gcloud cli to open SSH in PuTTY.
Install Jupyter notebook:
There are two ways to install Jupyter notebook, either by first installing anaconda package then Jupyter notebook or by first installing pip then Jupyter notebook. This tells us that Python is also needed to install Jupyter notebook. In Ubuntu, Python is there by default so we only need to install pip. In Windows OS as well we need python to be installed and pip or conda. In this blog, I will use pip since it is easier and lighter to install than anaconda.
In Ubuntu to install pip , first we need to update it:
sudo apt-get update
sudo apt-get install python-pip
After installing to install jupyter it is better to upgrade pip:
pip install --upgrade pip
Before install Jupyter notebook, install six package (version > = 1.11.0):
python -m pip install --user six==1.11.0
Then install Jupyter notebook:
python -m pip install --user jupyter
Now, we need to configure jupyter notebook so that we can access it through local machine in our browser. For that first we have to generate configure file for jupyter notebook:
jupyter notebook --generate-config
Now, open that configure file using any of favorite editor (nano, vim etc):
Then add these line to the file:
c = get_config()
c.NotebookApp.ip = '0.0.0.0'
c.NotebookApp.open_browser = False
c.NotebookApp.port = 5000
NOTE: In front of port line, you have to enter the tcp port number which you had set in the firewall rule.
Now, I would suggest to set password for jupyter notebook, so that you won’t have to give token again and again to open jupyter notebook later. To set password use:
jupyter notebook password
Now, you are fully set to start jupyter notebook, simply type:
Then go to your favorite browser, and type:
<external IP address of that instance >:<TCP port number>
To get install julia go to download page of Julia and copy the link of version you wish to download (I am downloading julia 1.1.1). Choose correct link for you OS I am download for Linux with correct architecture of your VM instance (32-bit or 64-bit), mine is 64-bit.
To download julia, use wget tool:
wget <copied link>
For Linux, first extract Julia for tar file:
tar -xvzf <downloaded file name>
tar -xvzf julia-1.1.1-linux-x86_64.tar.gz
Now, we need to add the bin folder path to the PATH environment variable and also add that to ~bashrc file:
echo 'export PATH=$PATH:<path to directory where the julia is extracted>/julia-1.1.1/bin' >> ~/.bashrcsource ~/.bashrc
Now, we can open julia by simply tying:
Now, to use Jupyter Notebook with Julia, we need to install IJulia package by julia package manager:
julia> using Pkg
This finishes all installations and now we can use jupyter notebook with julia:
julia> using IJulia
Then go to your browser and again type (in URL section):
<external IP address>:<TCp port>