Mac上的linux虚拟机踩坑日记
浏览器
arm64版本的chrome:sudo apt install chromium-browser
输入法
- 安装中文输入法:
sudo apt install ibus-rime - 系统设置 -> keyboard -> Input Source -> Add Input Source -> ... -> other -> Chinese(Rime)
fish
- 安装fish:
sudo apt install fish - 找到fish:
which fish,应该输入的是/usr/bin/fish chsh -s /usr/bin/fish
我目前的config保存
bash
parallels@ubuntu-linux-2404 ~> cat ~/.config/fish/config.fish
if status is-interactive
# Commands to run in interactive sessions can go here
# fish
set -g fish_greeting # 关闭默认的 fish 提示信息
# System - platform
if test (uname -m) = "arm64" || test (uname -m) = "aarch64"
echo "⚙️ platform: linux ARM64"
else
echo "⚙️ platform: linux x86_64"
end
# System - proxy
set -gx switch_proxy "on" # "on" or "off"
if test $switch_proxy = "on"
set -gx no_proxy "localhost,127.0.0.1,localaddress,.localdomain.com"
set -gx http_proxy "http://127.0.0.1:7897"
set -gx https_proxy $http_proxy
set -gx all_proxy "socks5://127.0.0.1:7897"
echo "✈️ proxy: $http_proxy"
else
echo "✈️ proxy: off"
end
# fnm
set FNM_PATH "/home/parallels/.local/share/fnm"
if [ -d "$FNM_PATH" ]
set PATH "$FNM_PATH" $PATH
fnm env | source
end
printf "🐢 "
fnm env --use-on-cd | source
set -gx nodev 22
if test $nodev = 16
fnm use 16.20.2
set -e NODE_OPTIONS # node 16需要开这个
end
if test $nodev = 18
fnm use 18.16.0
end
if test $nodev = 22
fnm use 22.15.0
end
end
fish美化
https://github.com/oh-my-fish/oh-my-fish/releases/
去下载oh-my-fish,然后去有install.sh的那个目录,./install.sh就可以了。
资料:https://www.cnblogs.com/aaroncoding/p/17118251.html
fnm
我们不能用apt去安装,fnm的github官方仓库为我们提供了支持fish的命令,直接运行curl -fsSL https://fnm.vercel.app/install | bash
docker
arm64版本没有docker-desktop版本,我们只能安装engine
首先下载gep
第一步
bash
# Add Docker's official GPG key:
sudo apt update
sudo apt install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
其中的curl这一步我下不下来,所以去浏览器下载了这个文件到~/downloads/gep,然后手动复制的
bash
parallels@ubuntu-linux-2404 ~ [1]> sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
curl: (35) Recv failure: Connection reset by peer
parallels@ubuntu-linux-2404 ~ [35]> sudo mkdir -p /etc/apt/keyrings
parallels@ubuntu-linux-2404 ~> sudo mv ~/Downloads/gpg /etc/apt/keyrings/docker.asc
parallels@ubuntu-linux-2404 ~> sudo chmod a+r /etc/apt/keyrings/docker.asc
parallels@ubuntu-linux-2404 ~>
第二步
官方的bash的命令
bash
# Add the repository to Apt sources:
sudo tee /etc/apt/sources.list.d/docker.sources <<EOF
Types: deb
URIs: https://download.docker.com/linux/ubuntu
Suites: $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}")
Components: stable
Signed-By: /etc/apt/keyrings/docker.asc
EOF
我改成了fish的命令
bash
set ubuntu_codename (lsb_release -cs)
echo "检测到 Ubuntu 版本: $ubuntu_codename"
echo "Types: deb
URIs: https://download.docker.com/linux/ubuntu
Suites: $ubuntu_codename
Components: stable
Signed-By: /etc/apt/keyrings/docker.asc" | sudo tee /etc/apt/sources.list.d/docker.sources
第三步的sudo apt update我出现了报错
然后我运行了
bash
# 更新 CA 证书
sudo apt install --reinstall ca-certificates
# 确保系统时间正确(TLS 需要准确时间)
sudo apt install ntpdate
sudo ntpdate pool.ntp.org
再去更新就没错饿了。
第四步,安装docker的一堆内容
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
第五步,验证docker打开了
sudo systemctl status docker
如果没打开,我们可以手动打开
sudo systemctl start docker
第六步,验证能不能运行hello world
sudo docker run hello-world
我不能运行,然后发现原来是我的梯子并没有生效,需要对守护进程也可见(为了方便,进入了bash操作的)
bash
# 1. 首先测试代理是否正常工作
curl -x http://127.0.0.1:7897 https://hub.docker.com/
# 2. 如果代理正常,为 Docker 配置代理
sudo mkdir -p /etc/systemd/system/docker.service.d
sudo tee /etc/systemd/system/docker.service.d/http-proxy.conf <<EOF
[Service]
Environment="HTTP_PROXY=http://127.0.0.1:7897"
Environment="HTTPS_PROXY=http://127.0.0.1:7897"
Environment="NO_PROXY=localhost,127.0.0.1"
EOF
# 3. 重启 Docker
sudo systemctl daemon-reload
sudo systemctl restart docker
# 4. 测试 Docker
sudo docker run hello-world
最后我们可以把用户加入docker组
bash
# 将当前用户加入 docker 组(请确保现在不是root)
sudo usermod -aG docker $USER
# 或者你直接指定你的账户
# sudo usermod -aG docker parallels
# 重新登录或刷新组权限
newgrp docker
# 验证是否生效
groups
# 重新登录或刷新组权限
newgrp docker
# 或者重启系统
sudo reboot