在 WSL 中配置一个开发用的 Alpine Linux

换源

sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories
apk update && apk upgrade --available

临时设置代理

# wsl1:
alias proxy="export all_proxy=http://127.0.0.1:7890 http_proxy=http://127.0.0.1:7890 https_proxy=http://127.0.0.1:7890"

# wsl2:
export host_ip=$(cat /etc/resolv.conf |grep "nameserver" |cut -f 2 -d " ")
alias proxy="export all_proxy=http://$host_ip:7890 http_proxy=http://$host_ip:7890 #https_proxy=http://$host_ip:7890"

# 上面二选一,然后执行下面
alias unproxy='unset all_proxy http_proxy https_proxy'
proxy

安装中文

apk add ca-certificates wget
wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub
wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.35-r0/glibc-2.35-r0.apk
wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.35-r0/glibc-bin-2.35-r0.apk
wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.35-r0/glibc-i18n-2.35-r0.apk

apk add --force-overwrite glibc-bin-2.35-r0.apk glibc-i18n-2.35-r0.apk glibc-2.35-r0.apk

/usr/glibc-compat/bin/localedef -i zh_CN -f UTF-8 zh_CN.UTF-8
export LANG=zh_CN.UTF-8 

使用apk安装的程序也只会显示英文,比如:vim date 执行结果都是英文,但是手动安装的软件已经可以显示中文了。

设置

# 添加普通用户
apk add sudo
NEWUSER='USERNAME'
adduser -g "${NEWUSER}" $NEWUSER
echo "$NEWUSER ALL=(ALL) ALL" > /etc/sudoers.d/$NEWUSER && chmod 0440 /etc/sudoers.d/$NEWUSER

# for XDE
adduser $NEWUSER video
adduser $NEWUSER input

# 安装zsh和omz以及配置
apk add zsh curl git

设置用户默认shell,按需修改HOME目录

自行替换下面的 NEWUSER 为用户名

vi /etc/passwd

## 修改以下内容:

NEWUSER:x:1000:1000:NEWUSER:/home/NEWUSER:/bin/ash

## 修改成

NEWUSER:x:1000:1000:NEWUSER:/PATH/TO/HOME/NEWUSER:/bin/zsh

修改wsl设置

vi /etc/wsl.conf

# 修改为下面这些内容

[interop]
appendWindowsPath = false

[user]
default=NEWUSER

然后结束wsl并重新登录

wsl --terminate alpine

设置zsh

alias proxy="export all_proxy=http://127.0.0.1:7890 http_proxy=http://127.0.0.1:7890 https_proxy=http://127.0.0.1:7890"
proxy

ZSH_DISABLE_COMPFIX=true

sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

#安装高亮显示插件
#我首先要做的是安装一个名为zsh-syntax-highlighting的插件。它为ZSH Shell提供语法高亮显示。

cd $HOME/.oh-my-zsh/custom/plugins
#下载代码
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git

# 自动补全zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-autosuggestions

vim ~/.zshrc

修改plugin项,加入zsh-autosuggestions zsh-syntax-highlighting

#.zshrc 内容

export LANG=zh_CN.UTF-8

alias proxy="export all_proxy=http://127.0.0.1:7890 http_proxy=http://127.0.0.1:7890 https_proxy=http://127.0.0.1:7890"
alias unproxy='unset all_proxy http_proxy https_proxy'
proxy

ZSH_DISABLE_COMPFIX=true
export ZSH=$HOME/.oh-my-zsh
ZSH_THEME="robbyrussell"
HIST_STAMPS="mm/dd/yyyy"
plugins=(git z zsh-autosuggestions zsh-syntax-highlighting)
source $ZSH/oh-my-zsh.sh

设置WSL的ssh同Windows

sudo apk add openssh

ssh原目录位置:

win: `%USERPROFILE%\.ssh`

linux: `~/.ssh`

新机执行:

ssh-keygen # 设置跟旧机一样就行
cd /path/to/old/ssh/folder/.ssh
cp * ~/.ssh/
cd ~/.ssh
chmod 600 id_rsa
chmod 644 id_rsa.pub

设置 VSCODE 环境

sudo apk update && apk add libstdc++

vim ~/.zshrc
# 添加下面到末尾
alias code="/mnt/c/Users/Windows用户名/AppData/Local/Programs/Microsoft\ VS\ Code/bin/code"

配置C++编译程序

sudo apk add gcc g++ gdb cmake make

安装Rust

sudo apk add rustup
rustup-init
# 更换国内源
vim ~/.cargo/config

# 内容

[http]
proxy = "127.0.0.1:7890"

[https]
proxy = "127.0.0.1:7890"

[source.crates-io]
replace-with = "rsproxy"

[source.ustc]
registry = "git://mirrors.ustc.edu.cn/crates.io-index"

[source.rsproxy]
registry = "https://rsproxy.cn/crates.io-index"

[registries.rsproxy]
index = "https://rsproxy.cn/crates.io-index"

安装Python

sudo apk add jq py3-configobj py3-pip py3-setuptools python3 python3

你可能感兴趣的:(WSL,笔记,linux,运维,服务器)