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
- 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.
- Install with
pip
- If you are installing with
pip
you need to follow all steps below.
- If you are installing with
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)username@host:~/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 enter8888
- 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.

Login using the password you set early.

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

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.