Created
October 18, 2025 04:39
-
-
Save chenxizhang/017095f64437d60e01f8262e0e7dc9fe to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -e # 遇到错误立即退出 | |
| set -o pipefail | |
| # ============ 基本设置 ============ | |
| echo "🚀 开始初始化 Ubuntu 环境..." | |
| sudo apt update -y && sudo apt upgrade -y | |
| # ============ 安装 zsh + oh-my-zsh ============ | |
| echo "💡 安装 Zsh 和 Oh My Zsh..." | |
| sudo apt install zsh curl git -y | |
| if [ ! -d "$HOME/.oh-my-zsh" ]; then | |
| RUNZSH=no CHSH=no KEEP_ZSHRC=yes sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" | |
| fi | |
| # 插件安装 | |
| echo "🔌 安装 Zsh 插件..." | |
| ZSH_CUSTOM=${ZSH_CUSTOM:-~/.oh-my-zsh/custom} | |
| git clone --depth=1 https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM}/plugins/zsh-autosuggestions || true | |
| git clone --depth=1 https://github.com/zsh-users/zsh-syntax-highlighting ${ZSH_CUSTOM}/plugins/zsh-syntax-highlighting || true | |
| # 修改插件配置 | |
| if grep -q "^plugins=" ~/.zshrc; then | |
| sed -i 's/^plugins=(.*)/plugins=(git zsh-autosuggestions zsh-syntax-highlighting)/' ~/.zshrc | |
| else | |
| echo "plugins=(git zsh-autosuggestions zsh-syntax-highlighting)" >> ~/.zshrc | |
| fi | |
| # 设置 zsh 为默认 shell | |
| if [ "$SHELL" != "$(which zsh)" ]; then | |
| echo "⚙️ 设置 Zsh 为默认 shell..." | |
| chsh -s "$(which zsh)" | |
| fi | |
| # ============ 安装 Docker ============ | |
| echo "🐳 安装 Docker..." | |
| curl -fsSL https://get.docker.com | sh | |
| sudo usermod -aG docker $USER || true | |
| # ============ 安装 uv ============ | |
| echo "🪄 安装 uv..." | |
| curl -LsSf https://astral.sh/uv/install.sh | sh | |
| # ============ 安装 GitHub CLI ============ | |
| echo "🐙 安装 GitHub CLI..." | |
| (type -p wget >/dev/null || (sudo apt update && sudo apt install wget -y)) | |
| sudo mkdir -p -m 755 /etc/apt/keyrings | |
| wget -qO- https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo tee /etc/apt/keyrings/githubcli-archive-keyring.gpg >/dev/null | |
| sudo chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg | |
| echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | \ | |
| sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null | |
| sudo apt update && sudo apt install gh -y | |
| # ============ 安装 NVM / Node / CLIs ============ | |
| echo "🟢 安装 NVM 与 Node..." | |
| export NVM_DIR="$HOME/.nvm" | |
| if [ ! -d "$NVM_DIR" ]; then | |
| curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash | |
| fi | |
| source "$NVM_DIR/nvm.sh" | |
| nvm install --lts | |
| nvm use --lts | |
| echo "🤖 安装 Copilot / Claude / Codex CLI..." | |
| npm install -g @github/copilot @anthropic-ai/claude-code @openai/codex | |
| # ============ 收尾 ============ | |
| echo "🎉 初始化完成!" | |
| echo "" | |
| echo "⚠️ 请执行以下命令以确保 Docker 权限立即生效:" | |
| echo " newgrp docker" | |
| echo "" | |
| echo "🔐 请手动登录相关账号:" | |
| echo " gh auth login" | |
| echo " docker login" | |
| echo "" | |
| echo "✅ 现在可以使用 zsh 了!输入命令: zsh" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment