Linux Environment Backup and JupyterHub Setup
R/Conda 环境备份与 JupyterHub 服务配置,方便系统重装后恢复工作环境。
R 包的备份与恢复
- 运行以下 R 代码,备份已安装包的列表,后续重新安装。
1 | # 保存 CRAN 包列表 |
-
备份 R 配置文件:
- 全局配置文件:
~/.Rprofile - 环境变量文件:
.Renviron - RStudio 配置:
~/.config/rstudio
- 全局配置文件:
-
恢复全局配置文件:将备份的
.Rprofile、.Renviron和 RStudio 配置复制到新系统的对应路径。 -
安装 R 包:
1 | installed_pkgs <- readLines("installed_packages.txt") |
- 安装时可能存在的问题:
- 依赖的系统库缺失:某些 R 包需要系统级依赖,需要在新系统中重新安装。
- 包版本冲突:指定版本安装,可查看先前保存的 R session 信息进行排查。
Conda 环境的备份与恢复
1 | 查看环境 |
JupyterHub 配置记录
NOTE: This tutorial copied from https://jupyterhub.readthedocs.io/en/stable/tutorial/quickstart.html 2025.06.06 with modification. Refer to the latest official document if you need.
由于 Linux 需要重做系统解决历史遗留问题,这里备份一下 JupyterHub 配置记录,方便后续复用。
JupyterHub is the best way to serve Jupyter notebook for multiple users. Because JupyterHub manages a separate Jupyter environment for each user, it can be used in a class of students, a corporate data science group, or a scientific research group. It is a multi-user Hub that spawns, manages, and proxies multiple instances of the single-user Jupyter notebook server.
Prerequisites
Before installing JupyterHub, we need:
- a Linux/Unix-based system: our Ubuntu 22.04
- Python version > 3.8 (we use 3.13.2)
Node.js18.0 (12.0 comes with errors), use NodeSource:
1 | 移除旧版 nodejs(可选) |
- Don't install with conda for the global usage in our system
- PAM is available by default
Installation
JupyterHub can be installed with pip (and the proxy with npm) or conda:
1 | sudo python3 -m pip install jupyterhub |
Test your installation. If installed, these commands should return the packages' help contents:
1 | jupyterhub -h |
Start the Hub server
To allow multiple users to sign in to the Hub server, you must start jupyterhub as a privileged user, such as root:
1 | sudo jupyterhub |
Modify configuration to allow multiple user login with their system account.
1 | sudo mkdir -p /etc/jupyterhub |
Add:
1 | # 允许所有系统用户登录 |
Use systemd to auto run JupyterHub when system start.
1 | sudo nano /etc/systemd/system/jupyterhub.service |
Add:
1 | [Unit] |
1 | 重新加载 systemd |
Enable frp
1 | sudo vi /home/network/frp/frp_0.62.1_linux_amd64/frpc.toml |
Add:
1 | [[proxies]] |
If not, using ssh tunnel.
JupyterHub Usage
JupyterHub running at server port 8888, Use ssh on your computer in terminal:
1 | ssh -L 8887:localhost:8888 user@39.102.66.182 -p 6005 |
Visit at your personal computer: localhost:8887 to use JupyterHub, login with your account.
For win, recommend use mobaxterm tunnel to get stable ssh tunnel.
user default work directory is /home/user.
Recommend adding kernel for yourself, for example (using conda):
1 | conda create -n your_env_name python=3.12 |
NOTE: Default system CUDA version: 11.5 Use
moduleto load cuda version 10.1 / 11.2 / 12.2
1 | module avail |
