Linux 系统环境配置指南
Published:
1. 代理配置
将以下内容添加到 ~/.bashrc,然后执行 source ~/.bashrc 使其生效:
alias proxy_on='
DEFAULT_HTTP_PROXY="http://127.0.0.1:7897"
DEFAULT_ALL_PROXY="socks5://127.0.0.1:7897"
http_proxy="$DEFAULT_HTTP_PROXY"
https_proxy="$DEFAULT_HTTP_PROXY"
ftp_proxy="$DEFAULT_HTTP_PROXY"
all_proxy="$DEFAULT_ALL_PROXY"
https_proxy="${https_proxy:-$http_proxy}"
ftp_proxy="${ftp_proxy:-$http_proxy}"
all_proxy="${all_proxy:-socks5://$(echo "$http_proxy" | sed "s#http://##")}"
export http_proxy="$http_proxy"
export https_proxy="$https_proxy"
export ftp_proxy="$ftp_proxy"
export all_proxy="$all_proxy"
export HTTP_PROXY="$http_proxy"
export HTTPS_PROXY="$https_proxy"
export FTP_PROXY="$ftp_proxy"
export ALL_PROXY="$all_proxy"
echo "🌐 代理已开启"
echo " http_proxy = $http_proxy"
echo " https_proxy = $https_proxy"
curl -I https://www.google.com --max-time 5 >/dev/null 2>&1 && \
echo "✅ Google 访问成功" || echo "❌ Google 访问失败"
'
# 关闭代理
alias proxy_off='
unset http_proxy;
unset https_proxy;
unset ftp_proxy;
unset all_proxy;
unset HTTP_PROXY;
unset HTTPS_PROXY;
unset FTP_PROXY;
unset ALL_PROXY;
echo "🛑 代理已关闭"
'
使用方式:
proxy_on # 开启代理
proxy_off # 关闭代理
2. Vim 配置
# 追加 vim 缩进配置(tab = 4 空格)
echo -e '\nset ts=4\nset softtabstop=4\nset shiftwidth=4\nset expandtab\nset autoindent' | sudo tee -a /etc/vim/vimrc
# 设置默认编辑器为 vim
sudo update-alternatives --set editor /usr/bin/vim.basic
3. Git 全局配置
# 查看配置
git config --list # 列出当前仓库配置
git config --global --list # 列出全局配置
# 设置代理
git config --global http.proxy http://127.0.0.1:7897
git config --global https.proxy http://127.0.0.1:7897
# 取消代理
git config --global --unset http.proxy
git config --global --unset https.proxy
4. 软件源与包管理
4.1 一键换源
# 使用 linuxmirrors.cn 一键换源
bash <(curl -sSL https://linuxmirrors.cn/main.sh)
4.2 安装常用包
# 编译工具链
sudo apt install -y build-essential
# 日常工具
sudo apt install -y tmux net-tools htop curl wget unzip tree
# Python 环境
sudo apt install -y python-is-python3 python3-pip
# 系统监控
sudo apt install -y neofetch btop
5. Docker 安装与配置
参考 ZJU Mirror;
5.1 安装依赖
sudo apt-get install -y apt-transport-https ca-certificates curl gnupg2 software-properties-common
5.2 添加 Docker 源
curl -fsSL https://mirrors.zju.edu.cn/docker-ce/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
# 添加 Docker APT 仓库
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://mirrors.zju.edu.cn/docker-ce/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
5.3 安装 Docker CE
# 安装 Docker Engine 及相关组件
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
5.4 配置国内镜像源:
5.5 用户组与验证
# 将用户加入 docker 组(免 sudo 使用 docker,需重新登录生效)
sudo usermod -aG docker username
# 验证安装
which docker # 确认 docker 路径
sudo docker ps # 验证 docker 安装
docker pull ubuntu:22.04 # 拉取测试镜像
docker ps # 列出运行中的容器
6. Claude Code / Codex
6.1 安装 Node.js 以及 agent
# 安装 nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
# 加载 nvm
\. "$HOME/.nvm/nvm.sh"
# 安装 Node.js v24
nvm install 24
# 验证版本
node -v
npm -v
# 全局安装 CLI 工具
npm install -g @anthropic-ai/claude-code
npm install -g @openai/codex
7. 常用命令
7.1 用户管理
# 创建用户
sudo useradd -m -s /bin/bash username # 创建用户并指定 shell
sudo passwd username # 设置用户密码
sudo usermod -aG sudo username # 添加 sudo 权限
# 查看用户信息
whoami # 当前用户名
id # 当前用户 UID/GID/组
cat /etc/passwd # 查看所有用户
groups # 查看当前用户所属组
7.2 文件与目录
# 符号链接
ln -s /path/to/target /path/to/link # 创建软链接
# 权限管理
chmod +x script.sh # 添加执行权限
chown user:group file # 修改文件所有者
7.3 系统信息
uname -a # 系统内核信息
lsb_release -a # Ubuntu 版本
df -h # 磁盘使用情况
free -h # 内存使用情况
uptime # 系统运行时间
