Install Jupyter Notebook on VPS for Data Science

Install Jupyter Notebook on VPS for Data Science

June 2026 · 7 min read

Jupyter Notebook on a VPS gives you the power of a remote server—more CPU, RAM, and disk than your laptop—accessible through your browser. You can run large-scale data processing, machine learning models, or Python scripts without waiting for your local machine to finish. This guide sets up Jupyter securely with password protection and SSL encryption.

Install Python and Jupyter

sudo apt update
sudo apt install python3 python3-pip python3-venv -y

# Create virtual environment (recommended)
python3 -m venv ~/jupyter-env
source ~/jupyter-env/bin/activate

# Install JupyterLab (more modern than Notebook)
pip install jupyterlab numpy pandas matplotlib scikit-learn

# Or classic Jupyter Notebook
pip install notebook

Configure Password and Settings

# Generate config file
jupyter lab --generate-config

# Set password
jupyter lab password
# Or
python3 -c "from jupyter_server.auth import passwd; print(passwd())"
nano ~/.jupyter/jupyter_lab_config.py
# Security configuration
c.ServerApp.ip = '127.0.0.1'         # bind localhost only
c.ServerApp.port = 8888
c.ServerApp.open_browser = False
c.ServerApp.notebook_dir = '/home/ubuntu/notebooks'
c.ServerApp.password = 'argon2:...'  # value from passwd() command

Access via SSH Tunnel (Most Secure Method)

# Run Jupyter on server
jupyter lab --no-browser

# Create tunnel from your laptop (in another terminal)
ssh -L 8888:localhost:8888 ubuntu@YOUR_VPS_IP

# Open browser
# http://localhost:8888
Tip: SSH tunnel is the most secure option—you don't expose port 8888 publicly and traffic is automatically encrypted through SSH. This method is ideal for single-user setups.

Set Up as systemd Service

sudo nano /etc/systemd/system/jupyter.service
[Unit]
Description=Jupyter Lab
After=network.target

[Service]
Type=simple
User=ubuntu
WorkingDirectory=/home/ubuntu
ExecStart=/home/ubuntu/jupyter-env/bin/jupyter lab --config=/home/ubuntu/.jupyter/jupyter_lab_config.py
Restart=always

[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable --now jupyter

Expose Publicly with Nginx + SSL (Optional)

sudo nano /etc/nginx/sites-available/jupyter

server {
    listen 443 ssl;
    server_name jupyter.yourdomain.com;

    ssl_certificate /etc/letsencrypt/live/jupyter.yourdomain.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/jupyter.yourdomain.com/privkey.pem;

    location / {
        proxy_pass http://127.0.0.1:8888;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";  # WebSocket support
        proxy_set_header Host $host;
    }
}

Verify Jupyter is Working Correctly

# Check service
systemctl status jupyter

# Check port
ss -tlnp | grep 8888

# Test via SSH tunnel
ssh -L 8888:localhost:8888 ubuntu@VPS_IP
# Open http://localhost:8888

# View logs
journalctl -u jupyter -n 50
Tip: Install additional data science libraries in your virtual environment: pip install tensorflow torch transformers seaborn plotly sqlalchemy This doesn't affect the VPS system Python installation.

Common Issues & Troubleshooting

Connection refused when accessing http://localhost:8888

SSH tunnel is not active or Jupyter is not running on your VPS. Check both sides:

# On VPS, verify Jupyter is running
ps aux | grep jupyter
ss -tlnp | grep 8888

# On your local machine, verify tunnel is active
ssh -L 8888:localhost:8888 ubuntu@VPS_IP -v 2>&1 | grep "Entering interactive"

Jupyter kernel dies during execution

The VPS is running out of memory or the Python process crashed. Check VPS memory and add swap if needed:

# Check memory while kernel is running
free -h

# Check kernel logs
journalctl -u jupyter | grep -i "error\|killed\|oom"

# Add swap if RAM is insufficient (see swap memory article)

Cannot install package in kernel

Your Jupyter kernel may be using a different Python than your virtualenv. Install packages directly through the kernel:

# In notebook cell
import sys
!{sys.executable} -m pip install package-name

# Or check which Python the kernel is using
import sys
print(sys.executable)

WebSocket connection failed when using Nginx

Nginx must set the upgrade header for WebSocket connections:

location / {
    proxy_pass http://127.0.0.1:8888;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_read_timeout 86400;  # Prevent timeout during long cell execution
}

Frequently Asked Questions

What's the difference between Jupyter Notebook and JupyterLab?

Jupyter Notebook is the original version with a simple UI. JupyterLab is the newer version with IDE-like features such as file browser, multiple tabs, and an extension marketplace. JupyterLab is now the recommended default.

How is Jupyter on a VPS better than Google Colab?

Google Colab is free but sessions end automatically after 12 hours, no persistent storage, and GPU availability is unstable. Jupyter on a VPS runs continuously, your data stays on your server, you can scale RAM/CPU as needed, and it costs less for heavy regular usage compared to Colab's limitations.

How do I set up auto-save and backup my notebooks?

Jupyter auto-saves every 2 minutes by default. Your .ipynb files are stored on the server. For backups, use rsync or git: cd ~/notebooks && git init && git add . && git commit -m "backup" then push to a private repository.