JupyterHub as a Service

JupyterHub as a Service

Setting up JupyterHub as a Service on Linux

Note: The original article can be found at https://davidadrian.cc/definitive-data-scientist-setup/.

Setting up JupyterHub as a server means that it will be available as soon as the PC boots up without manually launching it. To do this, you need miniconda installed.

  1. Create a Conda Virtual Environment:

    conda create -n jupyter_env python=3.9
    
  2. Activate the Environment:

    conda activate jupyter_env
    
  3. Install Necessary Libraries:

    conda install -c conda-forge jupyterhub jupyterlab nodejs nb_conda_kernels
    
  4. Create a Systemd Service File: Use sudo nano /etc/systemd/system/jupyterhub.service and fill it with the following content (ensure to replace <your_user> with your actual username):

    [Unit]
    Description=JupyterHub
    After=network.target
    
    [Service]
    User=root
    Environment="PATH=/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/home/<your_user>/miniconda3/envs/jupyter_env/bin:/home/<your_user>/miniconda3/bin"
    ExecStart=/home/<your_user>/miniconda3/envs/jupyter_env/bin/jupyterhub
    
    [Install]
    WantedBy=multi-user.target
    
  5. Reload the Service Daemon:

    sudo systemctl daemon-reload
    
  6. Start the JupyterHub Service:

    sudo systemctl start jupyterhub
    
  7. Enable JupyterHub Service: This will ensure it automatically starts at boot time.

    sudo systemctl enable jupyterhub
    
  8. Access JupyterHub: Navigate to localhost:8000 and log in using your Linux credentials.

  9. Use Jupyter: After logging in, you can access a full-fledged Jupyter server in classic mode (/tree) or the more recent JupyterLab (/lab).

The standout feature of this setup is its ability to detect kernels in all conda environments. This means you can access these kernels effortlessly. Simply install the required kernel in your desired environment (e.g., conda install ipykernel or conda install irkernel) and restart the Jupyter server from the JupyterHub control panel.


Original Source: The Definitive Data Scientist Environment Setup


© 2023. All rights reserved.