新电脑构建开发环境 🔗
- iterm2
- brew
- zsh, ohmyzsh
- golang, rust
- vscode
- hugo
- github
- direnv
- multipass 虚拟机
- 字体 fira code, cascadia code, jetbrains mono.
安装终端窗口工具 🔗
下载地址:https://iterm2.com/
安装 brew 🔗
/bin/bash -c "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install.sh)"
安装,切换为zsh,并安装oh my zsh -- shell辅助工具
可能遇到的问题
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused
解决方式: https://github.com/ohmyzsh/ohmyzsh/issues/9465
安装 golang 🔗
https://golang.org/doc/install
https://sourabhbajaj.com/mac-setup/Go/README.html
vim .bashrc
export GOPATH=$HOME/go-workspace # don't forget to change your path correctly! export GOROOT=/usr/local/opt/go/libexec export PATH=$PATH:$GOPATH/bin export PATH=$PATH:$GOROOT/bin
安装 vscode 🔗
https://code.visualstudio.com/docs/setup/mac
插件
安装 blog系统 🔗
Brew install Hugo
git pull origin master --allow-unrelated-histories
git submodule update --init --recursive
本地配置GitHub访问权限 🔗
在~下创建.ssh文件夹 ssh-keygen -t rsa -C “xxx@xx.com" 将公钥添加到github
go env -w GOPROXY=https://goproxy.cn
direnv 🔗
根据文件夹下的.envrc 临时改env变量。
mac上安装和使用虚拟机 🔗
why need it? 🔗
因为使用的是mac笔记本,实验和开发上需要利用linux环境下的工具(如gcc,gdb之类),所以在mac的宿主机上虚拟化出linux很有必要。
其他平台的方案 🔗
windows下 vscode 安装Windows Subsystem for Linux (WSL)插件,即可
VirtualBox supports only x86 hardware.
Ubuntu is available not only on x86 architectures, but also has ARM-based versions.
VMWare 虚拟机产品(付费)。
macos m1下安装虚拟机 🔗
- macbook的指令集 uname -a or uname -m
- 新m1芯片下是arm64
- 老intel芯片下是x86_64
在m1 arch下 virtual box和VMWare虚拟机产品不支持。
macos m1 arch 🔗
multipass 可以支持在macos下虚拟化出ubuntu操作系统,基本上满足了开发需求。
multipass find
multipass launch 22.04 -n primary -c 2 -m 4G -d 50G
multipass list 查看虚拟机IP
multipass shell
sudo apt install ubuntu-desktop xrdp -y
vsocde ssh到本地虚拟化出来的ubuntu系统。
遇到的问题 🔗
mac的host机器登陆到multipass虚拟机时公钥设置的问题。
#ssh ubuntu@192.168.64.2
ubuntu@192.168.64.2: Permission denied (publickey).
# ssh ubuntu@192.168.64.3
Load key ".ssh/id_rsa.pub" invalid format
ubuntu@192.168.64.3: Permission denied (publickey).
原因: 在宿主机~/.ssh/config中 IdentityFile ~/.ssh/id_rsa.pub。 配置错误。 公钥配置在vm的~/.ssh/authorized_keys中。 在宿主机上ssh时利用私钥进行登陆认证。 所以在宿主机IdentityFile ~/.ssh/id_rsa.pub -> IdentityFile ~/.ssh/id_rsa(私钥)。
通过mulipass client里open shell打开primary 实例,可能出现
Can't open instance, stuck in Starting phase。
原因: 上一部修改ubuntu中~/.ssh/authorized_keys时不是采用的append新public key,采用覆盖。 所以在修改authorized_keys时原有public key最好backup一份。 打开远程的文件夹包含大量文件时(例如打开linux kernel文件夹代码),出现Connection to server got closed. Server will not be restarted。
vs打开虚拟机里的大文件时出现的问题
Visual Studio Code is unable to watch for file changes in this large workspace" (error ENOSPC).
解决办法参考:https://code.visualstudio.com/docs/setup/linux#_visual-studio-code-is-unable-to-watch-for-file-changes-in-this-large-workspace-error-enospc
在multipass中阅读linux代码出现的空间不足问题
在linux-5.19下
ubuntu$ ctags -R
no left space on disk.
尝试调整虚拟机的disk资源限制。
sudo vim /var/root/Library/Application\ Support/multipassd/qemu/multipassd-vm-instances.json
更改primary的disk限制,重启启动vm后不起作用。
接着尝试:
sudo /Library/Application\ Support/com.canonical.multipass/bin/qemu-img info /var/root/Library/Application\ Support/multipassd/qemu/vault/instances/primary/ubuntu-22.04-server-cloudimg-arm64.img
sudo /Library/Application\ Support/com.canonical.multipass/bin/qemu-img snapshot -d suspend /var/root/Library/Application\ Support/multipassd/qemu/vault/instances/primary/ubuntu-22.04-server-cloudimg-arm64.img
sudo /Library/Application\ Support/com.canonical.multipass/bin/qemu-img resize /var/root/Library/Application\ Support/multipassd/qemu/vault/instances/primary/ubuntu-22.04-server-cloudimg-arm64.img +10G
Image resized.
https://multipass.run/docs/modify-an-instance#heading--set-the-cpu-ram-or-disk-of-an-instance
https://zhuanlan.zhihu.com/p/435237515 launch failed: cannot connect to the multipass socket 解决办法:sudo launchctl load /Library/LaunchDaemons/com.canonical.multipassd.plist
image resized成功,但是disk size仍然是5G。
// make menuconfig
problem:Unable to find the ncurses libraries
solved: sudo apt-get install ncurses-dev
ubuntu@brett:~/linux-master$ make
SYNC include/config/auto.conf.cmd
CALL scripts/checksyscalls.sh
HOSTCC certs/extract-cert
certs/extract-cert.c:21:10: fatal error: openssl/bio.h: No such file or directory
21 | #include <openssl/bio.h>
| ^~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [scripts/Makefile.host:111: certs/extract-cert] Error 1
make[1]: *** [scripts/Makefile.build:500: certs] Error 2
make: *** [Makefile:1990: .] Error 2
solved: https://github.com/TinkerBoard/debian_kernel/issues/26
make进行kernel的编译,之后会等一会...
LD [M] sound/soc/tegra/snd-soc-tegra210-sfc.ko
OBJCOPY arch/arm64/boot/Image
GZIP arch/arm64/boot/Image.gz
ubuntu@brett:~/linux-master$ file arch/arm64/boot/Image
arch/arm64/boot/Image: Linux kernel ARM64 boot executable Image, little-endian, 4K pages
github连接上的问题 🔗
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
SHA256:.....
Please contact your system administrator.
Add correct host key in /Users/brettkk/.ssh/known_hosts to get rid of this message.
Offending RSA key in /Users/brettkk/.ssh/known_hosts:2
Host key for [ssh.github.com]:443 has changed and you have requested strict checking.
Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
解决办法: 删除 ~/.ssh/known_hosts中的github那几行配置, 再pull下。
其他 🔗
本地安装付费的虚拟机。
购买云主机, 例如腾讯云的轻量应用服务器。