Installing Jupyter Notebooks on Ubuntu
Jupyter Notebooks have become an essential tool for data scientists, developers, and researchers. They offer a versatile environment for interactive coding, data visualization, and collaboration.
This guide provides a step-by-step walkthrough on how to install and configure Jupyter Notebooks on an Ubuntu 22.04 server. We’ll cover the installation of necessary packages, setting up a secure password, and running Jupyter Lab as a service for easy access. Whether you’re new to Jupyter Notebooks or looking to set up a test environment on your Ubuntu server, this tutorial will equip you with the knowledge and skills to get started.
Prerequisites
- Ubuntu 22.04: I will be using Ubuntu 22.04 throughout this demo. You can install your Ubuntu server in under 30 seconds from the Atlantic.Net Cloud Platform Console. You can find out how to build an Atlantic.Net VPS here.
- Basic Python Knowledge: Familiarity with Python and virtual environments is helpful.
Step 1 – Install Python
Jupyter Lab requires Python. You can install it using the following commands:
apt install python3 python3-pip -y
Next, install the Python virtual environment package.
pip install -U virtualenv
Step 2 – Install Jupyter Lab
Now, install the Jupyter Lab using the pip command.
pip3 install jupyterlab
This command installs Jupyter Lab and its dependencies. Next, edit the .bashrc file.
nano ~/.bashrc
Define your Jupyter Lab path as shown below; simply add it to the bottom of the file:
export PATH=$PATH:~/.local/bin/
Reload the changes using the following command.
source ~/.bashrc
Next, test run the Jupyter Lab locally using the following command to make sure everything starts.
jupyter lab --allow-root --ip=0.0.0.0 --no-browser
Check the output to make sure there are no errors, upon success you will see the following output.
[C 2023-12-05 15:09:31.378 ServerApp] To access the server, open this file in a browser:
http://ubuntu:8888/lab?token=aa67d76764b56c5558d876e56709be27446
http://127.0.0.1:8888/lab?token=aa67d76764b56c5558d876e56709be27446
Press the CTRL+C to stop the server.
Step 3 – Configure Jupyter Lab
By default, Jupyter Lab doesn’t require a password to access the web interface. To secure Jupyter Lab, generate the Jupyter Lab configuration using the following command.
jupyter-lab --generate-config
Output.
Writing default config to: /root/.jupyter/jupyter_lab_config.py
Next, set the Jupyter Lab password.
jupyter-lab password
Set your password as shown below:
Enter password:
Verify password:
[JupyterPasswordApp] Wrote hashed password to /root/.jupyter/jupyter_server_config.json
You can verify your hashed password using the following command.
cat /root/.jupyter/jupyter_server_config.json
Output.
{
"IdentityProvider": {
"hashed_password": "argon2:$argon2id$v=19$m=10240,t=10,p=8$zf0ZE2UkNLJK39l8dfdgHA$0qIAAnKiX1EgzFBbo4yp8TgX/G5GrEsV29yjHVUDHiQ"
}
}
Note this information, as you will need to add it to your config.
Next, edit the Jupyter Lab configuration file.
nano /root/.jupyter/jupyter_lab_config.py
Define your server IP, hashed password, and other configurations as shown below:
c.ServerApp.ip = 'your-server-ip'
c.ServerApp.open_browser = False
c.ServerApp.password = 'argon2:$argon2id$v=19$m=10240,t=10,p=8$zf0ZE2UkNLJK39l8dfdgHA$0qIAAnKiX1EgzFBbo4yp8TgX/G5GrEsV29yjHVUDHiQ'
c.ServerApp.port = 8888
Make sure you format the file exactly as above. For example, the port number is not in brackets, and the False boolean must have a capital F.
Save and close the file when you are done.
Step 4 – Create a Systemctl Service File for Jupyter Notebooks
Next, create a systemd service file to manage the Jupyter Lab.
nano /etc/systemd/system/jupyter-lab.service
Add the following configuration:
[Service]
Type=simple
PIDFile=/run/jupyter.pid
WorkingDirectory=/root/
ExecStart=/usr/local/bin/jupyter lab --config=/root/.jupyter/jupyter_lab_config.py --allow-root
User=root
Group=root
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
Save and close the file, then reload the systemd daemon.
systemctl daemon-reload
Next, start the Jupyter Lab service using the following command.
systemctl start jupyter-lab
You can now check the status of Jupyter Lab service using the following command.
systemctl status jupyter-lab
Jupyter Lab is now started and listening on port 8888. You can verify it with the following command.
ss -antpl | grep jupyter
Output.
LISTEN 0 128 104.219.55.40:8888 0.0.0.0:* users:(("jupyter-lab",pid=156299,fd=6))
Step 5 – Access Jupyter Notebooks Lab
Now, open your web browser and access the Jupyter Lab web interface using the URL http://your-server-ip:8888. You will see the Jupyter Lab on the following screen.
Provide the password you set during the installation and click on Log in. You will see Jupyter Lab dashboard on the following screen:
Step 6 – Start the Python3 Jupyter Notebooks
Select the icon Notebook: Python3 (PyKernel)
Thats it, you know now how to install Jupyter Notebooks on Ubuntu.
Recent Comments