How to Install Jupyter Notebook on a Vultr CentOS 7 Server Instance

Updated on November 21, 2023
How to Install Jupyter Notebook on a Vultr CentOS 7 Server Instance header image

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 a Vultr CentOS 7 server instance for remote access.

Prerequisites

Before getting started, you need to:

  • Deploy a fresh Vultr CentOS 7 server instance;
  • Log in from an SSH terminal as a non-root sudo user, and let's say the username is "juser". You can learn more about how to create such a sudo user in this Vultr article.

Step 1: Update the system and install dependencies

Use the following commands to update the system and install necessary packages for Jupyter Notebook.

sudo yum update -y
sudo yum install bzip2 -y
sudo shutdown -r now

After the reboot, use the same username and password to log into the system.

Step 2: Install Jupyter Notebook using Anaconda

Anaconda is an open data science platform consisting of many analytics applications, including Jupyter Notebook. By installing Anaconda, you will have installed Jupyter Notebook and many similar applications onto your system.

Download the appropriate version of Anaconda from the official Anaconda website to install it:

cd ~
wget http://repo.continuum.io/archive/Anaconda3-4.1.1-Linux-x86_64.sh
sudo bash Anaconda3-4.1.1-Linux-x86_64.sh

At the beginning the installation, continuously press ENTER until you are presented with question below:

Do you approve the license terms? [yes|no]

Answer yes, and then press ENTER:

>>> yes

Then you will be asked to confirm the installing location:

Anaconda3 will now be installed into this location:
/root/anaconda3

  - Press ENTER to confirm the location
  - Press CTRL-C to abort the installation
  - Or specify a different location below

You can specify the installing location /opt/anaconda3:

[/root/anaconda3] >>> /opt/anaconda3

When presented with the following question, press ENTER to finish the installation:

Do you wish the installer to prepend the Anaconda3 install location
to PATH in your /root/.bashrc ? [yes|no]

[no] >>> ENTER

Instead of modifying the per-user configuration file "/root/.bashrc", you can perform a system-wide setup modification for all users:

sudo cp /etc/profile /etc/profile_backup
echo 'export PATH=/opt/anaconda3/bin:$PATH' | sudo tee -a /etc/profile
source /etc/profile
echo $PATH

Step 3: Configure Jupyter Notebook

Now that Jupyter Notebook has been installed onto your system, you will need to configure it before you can access it remotely.

Generate a configuration file:

cd ~
jupyter notebook --generate-config

This command will create a default Jupyter Notebook configuration file: /home/juser/.jupyter/jupyter_notebook_config.py.

For security purposes, use the following commands to setup a password for your Jupyter Notebook server:

python
>>> from notebook.auth import passwd
>>> passwd()
Enter password:<your-password>
Verify password:<your-password>
'sha1:<your-sha1-hash-value>'
>>> Ctrl+Z

Save the SHA1 hash value for later use, which will look like: sha1:49acd1a985cc:beb1fb6859665bfa721e65e78fc511c41b12e7ce.

Create a self-signed certificate and the matched key:

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

The above command will generate a certificate file /home/juser/jcert.pem and the matched key file /home/juser/jkey.key.

Open the default configuration file using the vi editor:

vi /home/juser/.jupyter/jupyter_notebook_config.py

Find each line below respectively:

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

Modify each of them as below:

c.NotebookApp.certfile = '/home/juser/jcert.pem'
# for users with root you can use './jcert.pem'
c.NotebookApp.keyfile = '/home/juser/jkey.key'
# for users with root you can use './jkey.key'
c.NotebookApp.ip = '*'
c.NotebookApp.open_browser = False
c.NotebookApp.password = 'sha1:<your-sha1-hash-value>'
c.NotebookApp.port = 8888

Save and quit:

:wq!

Modify firewall rules in order to allow inbound traffic on port 8888:

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

Start the Jupyter Notebook server:

jupyter notebook

Finally, visit "https://<your-server-IP>:8888" from your browser, ignore the security warning, and use the password you set earlier to log in.