Compute Engine Google Cloud

How to Set Up Jupyter Notebook on Ubuntu 18.04 in Google Cloud

How to Set Up Jupyter Notebook on Ubuntu 18.04 in Google Cloud. Jupyter is an open source software for interactive computing across many programming languages. Jupyter Notebook is a web application which is used to create and share live codes, equations, visualizations. This used in machine learning, data cleaning, numerical simulation, statistical modeling and many more.

In this guide you are going to learn how to setup Jupyter Notebook on Ubuntu in Google Cloud Platform.

Prerequisites

Your Compute Engine Instance running, see the Setting up Compute Engine Instance.

Installation Methods

You can install Jupyter Notebook with two different methods

  1. Install using Anaconda. Learn to install Jupyter Notebook using Anaconda
    • If you are installing using Anaconda you can skip the below steps up to creating Firewall rules.
  2. Install with pip
    • If you are installing with pip you need to follow all steps below.

Install required packages

SSH to your Compute Engine instance and begin typing the following commands to start installing Jupyter.

sudo apt install python3-dev python3-pip

Create Python Virtual Environment for Jupyter Notebook

sudo -H pip3 install --upgrade pip
sudo -H pip3 install virtualenv
mkdir ~/myprojectdir
cd ~/myprojectdir
virtualenv myprojectenv

Activate the virtual environment by typing

source myprojectenv/bin/activate

Your prompt should change to indicate that you are now operating within a Python virtual environment. It will look something like this: (myprojectenv)[email protected]:~/myprojectdir$

Install Jupyter Notebook

Now you can install Jupyter Notebook using pip

pip install jupyter

Enable Firewall Rule

Once Jupyter Notebook is installed it will run on port 8888. So you need to create a Firewall rule to allow connections on port 8888. So lets create a firewall rule.

Go to Networking >> VPC Networks >> Firewall rules and click Create Firewall rule.

  • Enter a name
  • In Targets select All instances in the network
  • In Source IP ranges enter 0.0.0.0/0
  • In Protocols and ports check tcp and enter 8888
  • Click Create

Configure Jupyter Notebook

By default Jypyter Notebook listens on localhost only, so you need to create a configuration to allow external connections.

Generate Configuration

jupyter notebook --generate-config

Now a configuration file will be created in /home/username/.jupyter/jupyter_notebook_config.py

Edit the file and find c.NotebookApp.ip and remove the # and replace localhost with 0.0.0.0

sudo nano /home/username/.jupyter/jupyter_notebook_config.py

So the final code will be like this:

c.NotebookApp.ip = '0.0.0.0'

Generate Password

Finally you can secure the application by creating a password.

jupyter notebook password

Enter the password and verify the password.

Test Jupyter Notebook

Now Jupyter Notebook is installed and also created a firewall rule to allow access on port 8888. Now start Jupyter notebook.

jupyter notebook

Visit your IP Address with port 8888 (http://IP_ADDRESS:8888/)on your bowser.

Jupyter Notebook Login

Login using the password you set early.

Jupyter notebook dashboard

Now you can write codes, equations, etc on your Jupyter Notebook.

Jupyter Notebook directory structure

You can click on Quit button to shutdown Jupyter Notebook server. For more set up and configuration details you can visit official docs here.

Great!

Jupyter Notebook is installed successfully on your Ubuntu 18.04 in Google Cloud.

Cloudbooklet builds a large collection of Linux based guides and tutorials on Cloud platforms like Google Cloud, AWS, Azure, DigitalOcean and more

Write A Comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

If you find this helpful? Support me!
Buy me a coffee Donation Please buy me a coffee