Learn How To Install Jupyter Notebook on a Ubuntu 16.04 Server Instance

January 3, 2020

Table of Contents

If you are using a different system, please check our other tutorials.

Introduction

Jupyter Notebook, derived from IPython, is a widely used, interactive data science web application which can be used to create and share scientific computing-related documents.

This article will show you how to install Jupyter Notebook on An ITWeb.Services Ubuntu 16.04 server instance for remote access using Python3 and pip.

Prerequisites

Before getting started, you need to:

  • Deploy a fresh IT Web Services Ubuntu 16.04 server instance.
  • https://www.itweb.services/tutorials/linux-guides/how-to-use-sudo-on-debian-centos-and-freebsd”>non-root sudo user, and let’s say the username is “juser“. You should follow the Debian instructions but execute /etc/init.d/ssh restart instead of /etc/init.d/sshd restart.

Update the system and install PIP

Use the following commands to update the system:

sudo apt-get update -y
sudo apt-get install python3-pip -y
pip3 install --upgrade pip

Install Jupyter Notebook

Install Jupyter Notebook.

sudo apt-get install python3-setuptools -y
sudo pip3 install jupyter

Configure Jupyter

Before configuring Jupyter Notebook, we’ll need to make a config file, to do so, let’s move to our home directory and make a new one.

cd ~
jupyter notebook --generate-config

Next, let’s create a hashed password for our server, execute the following command and follow the instructions.

jupyter notebook password

For the sake of this tutorial, let’s say the password is “jupyter“. This will create the hash and save it in your jupyter_notebook_config.json which will be located at ~/.jupyter/jupyter_notebook_config.json.

Now, since we want at least some security let’s make an SSL certificate under the .jupyter/cert directory.

cd .jupyter
mkdir cert
cd cert
openssl req -x509 -nodes -days 365 -newkey rsa:4096 -keyout jkey.key -out jcert.pem

Now let’s edit the jupter_notebook_config.py. Open it with your favorite text editor and find the following lines, uncomment them, and change them as shown below.

Before editing.

#c.NotebookApp.password = ''
#c.NotebookApp.port = 8888
#c.NotebookApp.ip = 'localhost'
#c.NotebookApp.open_browser = False
#c.NotebookApp.certfile = ''
#c.NotebookApp.keyfile = ''

After editing.

c.NotebookApp.password = 'sha1:<your sha hashed password>'
c.NotebookApp.port = 8888
c.NotebookApp.ip = '*'
c.NotebookApp.open_browser = False
c.NotebookApp.certfile = '/home/juser/.jupyter/cert/jcert.pem'
c.NotebookApp.keyfile = '/home/juser/.jupyter/cert/jkey.key'

Note: Remember your hashed password was saved under ~/.jupyter/jupyter_notebook_config.json.

Modify firewall

Modify the firewall rules.

sudo apt-get install firewalld -y
sudo firewall-cmd --zone=public --add-port=8888/tcp --permanent
sudo systemctl restart firewalld.service

Conclusion

Run Jupyter Notebook with the command jupyter notebook, and visit https://<your server ip>:8888, ignore the security warning and use the password set earlier.

Remember you can run it with nohup if you want to log out and keep it running.

nohup jupyter notebook &

Need help?

Do you need help setting up this on your own service?
Please contact us and we’ll provide you the best possible quote!