跳转到内容

环境配置

此内容尚不支持你的语言。

使用 set 命令设置环境变量, 只对当前终端有效:

Terminal window
set JAVA_HOME=C:\Program Files\Java\jdk-17
set PATH=%JAVA_HOME%\bin;%PATH%

使用 setx 命令设置永久环境变量:

Terminal window
# 设置用户变量
setx JAVA_HOME "C:\Program Files\Java\jdk-17"
# 设置系统变量 (需要管理员权限)
setx /M JAVA_HOME "C:\Program Files\Java\jdk-17"

临时设置 (只对当前终端有效):

Terminal window
export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
export PATH=$JAVA_HOME/bin:$PATH

永久设置:

根据使用的 Shell 配置文件:

  • Bash: ~/.bashrc
  • Zsh: ~/.zshrc
  • Fish: ~/.config/fish/config.fish
Terminal window
# 将环境变量写入配置文件
echo 'export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64' >> ~/.bashrc
echo 'export PATH=$JAVA_HOME/bin:$PATH' >> ~/.bashrc
# 重新加载配置
source ~/.bashrc
变量名描述
PATH可执行文件搜索路径
JAVA_HOMEJava 安装路径
M2_HOMEMaven 安装路径
GRADLE_HOMEGradle 安装路径
ANDROID_HOMEAndroid SDK 路径
GOPATHGo 工作区路径
GOROOTGo 安装路径
PYTHONPATHPython 模块搜索路径
NODE_PATHNode.js 模块搜索路径
http_proxyHTTP 代理
https_proxyHTTPS 代理
no_proxy不使用代理的域名
Terminal window
# Windows
set # 查看所有环境变量
set JAVA_HOME # 查看特定变量
# Linux / macOS
env # 查看所有环境变量
echo $JAVA_HOME # 查看特定变量
Terminal window
# 临时设置
export http_proxy=http://127.0.0.1:7890
export https_proxy=http://127.0.0.1:7890
export all_proxy=socks5://127.0.0.1:7890
# 不使用代理的域名
export no_proxy="localhost,127.0.0.1,.local,.internal"

常用代理软件端口:

软件HTTP 代理Socks5 代理
Clash78907890
V2RayN1080910808
Shadowsocks10801080

配置 Git Bash 为默认终端:

  1. 打开 Windows Terminal 设置
  2. 点击 “添加新配置文件”
  3. 填写以下信息:
    • 名称: Git Bash
    • 命令行: C:\Program Files\Git\bin\bash.exe --login -i
    • 起始目录: %USERPROFILE%
    • 图标: C:\Program Files\Git\mingw64\share\git\git-for-windows.ico
  4. 将 Git Bash 设置为默认配置文件

注意: 使用 --login 参数以确保 .bash_profile 被正确加载

PowerShell 配置文件位置:

配置类型路径
当前用户, 当前主机$HOME\Documents\PowerShell\Microsoft.PowerShell_profile.ps1
当前用户, 所有主机$HOME\Documents\PowerShell\profile.ps1
所有用户, 当前主机$PSHOME\Microsoft.PowerShell_profile.ps1
所有用户, 所有主机$PSHOME\profile.ps1

常用配置:

Terminal window
# 查看配置文件路径
$profile
# 编辑配置文件
notepad $profile

Zsh 配置文件加载顺序:

  1. .zshenv - 总是读取
  2. .zprofile - 登录 shell 读取
  3. .zshrc - 交互式 shell 读取
  4. .zlogin - 登录 shell 读取

常用配置:

Terminal window
# 别名配置
alias ll='ls -alh'
alias gs='git status'
alias gc='git commit'
alias gp='git push'
# 路径配置
export PATH="$HOME/.local/bin:$PATH"
# 代理配置
proxy() {
export http_proxy=http://127.0.0.1:7890
export https_proxy=http://127.0.0.1:7890
export all_proxy=socks5://127.0.0.1:7890
echo "Proxy enabled"
}
noproxy() {
unset http_proxy
unset https_proxy
unset all_proxy
echo "Proxy disabled"
}

推荐使用版本管理工具来管理多版本的开发环境:

语言/工具版本管理工具
JavaSDKMAN!
Node.jsnvm-windows, fnm
Pythonpyenv, conda
Gogoenv
Rustrustup
Rubyrbenv
PHPphpenv
Terminal window
# 使用 SDKMAN! 安装
sdk install java 17.0.9-tem
# 环境变量 (手动安装时)
export JAVA_HOME=/path/to/jdk
export PATH=$JAVA_HOME/bin:$PATH
Terminal window
# 使用 SDKMAN! 安装
sdk install maven
# 环境变量 (手动安装时)
export M2_HOME=/path/to/maven
export PATH=$M2_HOME/bin:$PATH
# 配置阿里云镜像 (settings.xml)
# <mirror>
# <id>aliyun</id>
# <mirrorOf>central</mirrorOf>
# <name>Aliyun Maven</name>
# <url>https://maven.aliyun.com/repository/public</url>
# </mirror>
Terminal window
# 使用 fnm 安装
fnm install 20
fnm use 20
# npm 镜像配置
npm config set registry https://registry.npmmirror.com
# pnpm 镜像配置
pnpm config set registry https://registry.npmmirror.com
Terminal window
# 环境变量
export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export PATH=$GOROOT/bin:$GOPATH/bin:$PATH
# 模块代理
go env -w GOPROXY=https://goproxy.cn,direct
go env -w GOPRIVATE=*.example.com
Terminal window
# 使用 conda 创建环境
conda create -n myenv python=3.11
conda activate myenv
# pip 镜像配置
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
Terminal window
# 使用 rustup 安装
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# 镜像配置 (国内)
export RUSTUP_DIST_SERVER=https://rsproxy.cn
export RUSTUP_UPDATE_ROOT=https://rsproxy.cn/rustup
名称地址
阿里云https://developer.aliyun.com/mirror/
腾讯云https://mirrors.cloud.tencent.com/
华为云https://mirrors.huaweicloud.com/
清华大学https://mirrors.tuna.tsinghua.edu.cn/
中国科学技术大学https://mirrors.ustc.edu.cn/
  • npm: https://registry.npmmirror.com
  • Maven: https://maven.aliyun.com/repository/public
  • PyPI: https://pypi.tuna.tsinghua.edu.cn/simple
  • Go: https://goproxy.cn
  • Rust: https://rsproxy.cn
  • Docker Hub: https://docker.1ms.run

配置文件位置:

  • Windows: %APPDATA%\Code\User\settings.json
  • macOS: ~/Library/Application Support/Code/User/settings.json
  • Linux: ~/.config/Code/User/settings.json

推荐安装的扩展:

扩展名称用途
Chinese (Simplified) Language Pack中文语言包
GitLensGit 增强
Error Lens行内错误提示
Todo TreeTodo 管理
Remote - SSH远程开发
Dev Containers容器开发

配置文件位置:

  • Windows: %APPDATA%\JetBrains\IntelliJIdea2024.1
  • macOS: ~/Library/Application Support/JetBrains/IntelliJIdea2024.1
  • Linux: ~/.config/JetBrains/IntelliJIdea2024.1

推荐配置:

  • 自动导入: Settings → Editor → General → Auto Import
  • 编码: Settings → Editor → File Encodings → UTF-8
  • Maven: Settings → Build, Execution, Deployment → Build Tools → Maven
Terminal window
# 生成 RSA 密钥
ssh-keygen -t rsa -b 4096 -C "your.email@example.com"
# 生成 Ed25519 密钥 (推荐)
ssh-keygen -t ed25519 -C "your.email@example.com"

配置文件位置: ~/.ssh/config

# 通用配置
Host *
ServerAliveInterval 60
ServerAliveCountMax 3
ForwardAgent yes
# GitHub
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519
# 开发服务器
Host dev
HostName 192.168.1.100
User developer
Port 22
IdentityFile ~/.ssh/dev_key
Terminal window
# 方法 1: 使用 ssh-copy-id
ssh-copy-id user@server
# 方法 2: 手动添加
cat ~/.ssh/id_ed25519.pub | ssh user@server "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
Terminal window
# 设置用户名和邮箱
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
# 设置默认编辑器
git config --global core.editor "code --wait" # VS Code
git config --global core.editor "vim" # Vim
# 设置默认分支名
git config --global init.defaultBranch main
# 大小写敏感
git config --global core.ignorecase false
Terminal window
# 显示中文文件名
git config --global core.quotepath false
# 中文日志编码
git config --global i18n.logoutputencoding utf-8
# Windows 上的配置
git config --global core.autocrlf input
Terminal window
git config --global alias.st status
git config --global alias.co checkout
git config --global alias.ci commit
git config --global alias.br branch
git config --global alias.lg "log --graph --oneline --all"
Terminal window
# 列出 GPG 密钥
gpg --list-secret-keys --keyid-format=long
# 配置 Git 使用 GPG 签名
git config --global user.signingkey YOUR_KEY_ID
git config --global commit.gpgsign true
git config --global tag.gpgsign true
# 导出公钥并添加到 GitHub/GitLab
gpg --armor --export YOUR_KEY_ID
Terminal window
# 全局代理
git config --global http.proxy http://127.0.0.1:7890
git config --global https.proxy http://127.0.0.1:7890
# 针对特定域名
git config --global http."https://github.com".proxy http://127.0.0.1:7890
# 取消代理
git config --global --unset http.proxy
git config --global --unset https.proxy
t1