modelscope / Jupyterlab.sh
HOPStudio's picture
Upload 6 files
bac19c2 verified
Raw
History Blame Contribute Delete
936 Bytes
#!/bin/bash
# 更新系统包
sudo apt update
# 使用现有的 Python 安装 JupyterLab
pip install jupyterlab
# 为 JupyterLab 生成配置文件(如果不存在)
if [ ! -f ~/.jupyter/jupyter_lab_config.py ]; then
jupyter lab --generate-config
fi
# 设置 JupyterLab 服务文件
SERVICE_FILE=/etc/systemd/system/jupyterlab.service
sudo bash -c "cat > $SERVICE_FILE" <<EOL
[Unit]
Description=JupyterLab
After=network.target
[Service]
Type=simple
User=$(whoami)
ExecStart=$(which jupyter) lab --ip=0.0.0.0 --port=8888 --no-browser
WorkingDirectory=$HOME
Restart=always
[Install]
WantedBy=multi-user.target
EOL
# 重新加载 systemd 并启动 JupyterLab 服务
sudo systemctl daemon-reload
sudo systemctl start jupyterlab
sudo systemctl enable jupyterlab
# 输出服务状态
sudo systemctl status jupyterlab
echo "JupyterLab 已安装并配置为后台服务,您可以通过 http://<服务器IP>:8888 访问它。"