树莓派初始化与配置指南

stevessr · 2025-1-5 · 次阅读


yet , again

使用官方raspberry pi OS (64bit)在树莓派3B+上使用Kingston 64G TF卡,并更新到debian sid版本

step 1 : 安装系统

当然是使用Raspberry Pi Imager了

step 2 : 初始化系统

export http_proxy="http://192.168.127.66:7891"
#这个只管http连接
export https_proxy="http://192.168.127.66:7891"
#这个才关https连接

step 3 : 安装常用软件

nodejs

# 安装 fnm (快速 Node 管理器)
curl -fsSL https://fnm.vercel.app/install | bash

# 激活 fnm
source ~/.bashrc

# 下载并安装 Node.js
fnm use --install-if-missing 22

# 验证环境中是否存在正确的 Node.js 版本
node -v # 应该打印 `v22.12.0`

# 验证环境中是否存在正确的 npm 版本
npm -v # 应该打印 `10.9.0`

pnpm

curl -fsSL https://get.pnpm.io/install.sh | sh -
# or
wget -qO- https://get.pnpm.io/install.sh | sh -

rust

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

golang

sudo apt install golang

/etc/apt/sources.list

# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb  [arch=arm64] https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
deb-src [arch=arm64] https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware

deb [arch=arm64] https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
deb-src [arch=arm64] https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware

deb [arch=arm64] https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
deb-src [arch=arm64] https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware

# 以下安全更新软件源包含了官方源与镜像站配置,如有需要可自行修改注释切换
deb [arch=arm64] https://security.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware
deb-src [arch=arm64] https://security.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware

如果你要升级到sid

# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb  [arch=arm64] https://mirrors.tuna.tsinghua.edu.cn/debian/ sid main contrib non-free non-free-firmware
deb-src [arch=arm64] https://mirrors.tuna.tsinghua.edu.cn/debian/ sid main contrib non-free non-free-firmware
sudo apt update -y
sudo apt upgrade -y
sudo apt autoremove -y

neovim

very important : 为了这个而升级到sid版本

sudo apt update
sudo apt install neovim -y

lazy.nvim

--  require("config.lazy")
require("config.lazy")
--  ~/.config/nvim/lua/config/lazy.lua
-- Bootstrap lazy.nvim  
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"  
if not (vim.uv or vim.loop).fs_stat(lazypath) then  
local lazyrepo = "https://github.com/folke/lazy.nvim.git"  
local out = vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath })  
if vim.v.shell_error ~= 0 then  
vim.api.nvim_echo({  
{ "Failed to clone lazy.nvim:\n", "ErrorMsg" },  
{ out, "WarningMsg" },  
{ "\nPress any key to exit..." },  
}, true, {})  
vim.fn.getchar()  
os.exit(1)  
end  
end  
vim.opt.rtp:prepend(lazypath)  
  
-- Make sure to setup `mapleader` and `maplocalleader` before  
-- loading lazy.nvim so that mappings are correct.  
-- This is also a good place to setup other settings (vim.opt)  
vim.g.mapleader = " "  
vim.g.maplocalleader = "\\"  
  
-- Setup lazy.nvim  
require("lazy").setup({  
spec = {  
-- import your plugins  
{ import = "plugins" },  
},  
-- Configure any other settings here. See the documentation for more details.  
-- colorscheme that will be used when installing plugins.  
install = { colorscheme = { "habamax" } },  
-- automatically check for plugin updates  
checker = { enabled = true },  
})

pipx

sudo apt update 
sudo apt install pipx 
pipx ensurepath

zsh

sudo apt install zsh

oh my zsh

sh -c "$(curl -fsSL https://install.ohmyz.sh/)"
# or 
sh -c "$(wget -O- https://install.ohmyz.sh/)"
# or
sh -c "$(fetch -o - https://install.ohmyz.sh/)"

vscode(server)

#先创建一个专用用户
sudo useradd -m pi_dev
sudo usermod -aG sudo pi_dev
sudo usermod -s /bin/zsh pi_dev
#设置密码
sudo passwd pi_dev
su pi_dev
mkdir ~/.ssh
#使用sftp上传你的ssh公钥
  • 启动vscode
  • 在vscode中安装Remote Development插件(Microsoft开发的)
  • 按F1或Ctrl+Shift+P打开控制面板
  • 选择 Remote-SSH: Connect to Host… 命令
  • 这里输入树莓派的登陆用户名和主机IP,即准备工作中新建的pi_dev用户,务必替换你的实际IP地址
  • 连接到远程主机时,首先会要求我们选择系统类型(Windows/Linux/macOS),根据实际情况选择即可
  • 会自动配置vscode服务器端

安装远程桌面

sudo apt install xrdp
sudo /etc/init.d/xrdp restart

如果你想禁用

sudo systemctl stop xrdp
sudo killall xrdp-sessman xrdp-chansrv xrdp
systemctl status xrdp
sudo systemctl disable xrdp

安装Raspberry Pi Connect

sudo apt update
sudo apt full-upgrade
sudo apt autoremove
sudo apt install rpi-connect
rpi-connect on
rpi-connect vnc on

如果桌面变回LXDE原生

sudo apt install fastfetch -y
sudo apt install xorg -y
sudo apt install lxde openbox -y
sudo apt install rpd-plym-splash rpd-wallpaper rp-bookshelf -y

卸载snap

for p in $(snap list | awk '{print $1}'); do  
  sudo snap remove $p  
done
for p in $(snap list | awk '{print $1}'); do  
  sudo snap remove $p  
done
# 直到提示
#No snaps are installed yet. Try 'snap install hello-world'.
sudo systemctl stop snapd  
sudo systemctl disable --now snapd.socket  
  
for m in /snap/core/*; do  
   sudo umount $m  
done

sudo apt autoremove --purge snapd

rm -rf ~/snap  
sudo rm -rf /snap  
sudo rm -rf /var/snap  
sudo rm -rf /var/lib/snapd  
sudo rm -rf /var/cache/snapd