超详细教学!树莓派(4)ubuntu(22.04)中文汉化与thonny安装(保姆级教学)
本文是我在树莓派4ubuntu22.04下各种环境配置,内容亲测有效。在各种资料里跌跌撞撞几天终于在踩坑后,总结了以下内容。包括交换分区,中文环境配置,摄像头安装,换源。
目录
前言
本文是我在树莓派4ubuntu22.04下各种环境配置,内容亲测有效。在各种资料里跌跌撞撞几天终于在踩坑后,总结了以下内容。
包括交换分区,中文环境配置,摄像头安装,换源。
一、Ubuntu22.04安装
详情见我第一篇文章。
二、换源
1.备份原有源文件
ubuntu桌面ctrl+alt+t打开终端
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
2.修改软件源配置文件:
sudo nano /etc/apt/sources.list
3. 替换为国内镜像源
1清华大学镜像源(推荐)
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-security main restricted universe multiverse
2阿里云镜像源
deb http://mirrors.aliyun.com/ubuntu-ports/ jammy main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu-ports/ jammy-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu-ports/ jammy-backports main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu-ports/ jammy-security main restricted universe multiverse
3 中科大镜像源
deb https://mirrors.ustc.edu.cn/ubuntu-ports/ jammy main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu-ports/ jammy-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu-ports/ jammy-backports main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu-ports/ jammy-security main restricted universe multiverse
4 更新软件包列表
sudo apt update
sudo apt upgrade -y
5 恢复默认源:
若更换后出现问题,可通过备份文件还原:
sudo cp /etc/apt/sources.list.bak /etc/apt/sources.list
sudo apt update
三 中文环境
1. 更新系统
首先确保系统软件包是最新的:
sudo apt update && sudo apt upgrade -y
2. 安装中文语言包
sudo apt install language-pack-zh-hans -y # 简体中文语言包
3.配置系统语言
sudo dpkg-reconfigure locales
在弹出的界面中:
-
按空格键勾选
zh_CN.UTF-8(简体中文)。 -
按 Tab 键选择
OK并回车。 -
将默认系统语言设置为
zh_CN.UTF-8。
4.设置区域格式
编辑配置文件,设置中文区域:
sudo nano /etc/default/locale
修改内容为:
LANG=zh_CN.UTF-8
LANGUAGE=zh_CN:zh
LC_ALL=zh_CN.UTF-8
Ctrl+o后回车(保存)Ctrl+x(退出)
保存后重启系统:
sudo reboot
5.配置中文输入法
1 安装输入法框架
推荐使用 Fcitx + Google Pinyin:
sudo apt install fcitx fcitx-googlepinyin -y
2 配置输入法
-
重启系统或注销后重新登录。
-
打开终端,运行:
fcitx-config-gtk3
-
点击左下角
+,取消勾选Only Show Current Language,搜索并添加Google Pinyin。 -
通过
Ctrl+空格切换输入法。
6 验证中文环境
-
检查系统语言:
-
locale # 输出应为 zh_CN.UTF-8到此中文设置完成。
四,交换分区
1.来查看系统是否有交换分区
sudo swapon --show
然后你会发现没有提示,那么就是没有交换空间。
检查磁盘的使用情况
df -h
2. 创建交换分区
输入
sudo fallocate -l 2G /swapfile
树莓派4B适合设置2G
更改权限
ls -lh /swapfile
sudo chmod 600 /swapfile
3. 标记交换文件
sudo mkswap /swapfile
4. 启动交换文件
sudo swapon /swapfile #打开交换空间
#sudo swapoff /swapfile 关闭交换空间
查看是否成功
sudo swapon --show
free -h
5. 永久保存
sudo cp /etc/fstab /etc/fstab.bak #备份系统文件
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
到这里就设置好交换分区
五 安装thonny(python集成环境)
1 安装(在清华源下)
Thonny是一个Python IDE,常用于树莓派上的Python编程,特别是针对教育用户和初学者。用户可能需要在Ubuntu上安装Thonny来进行Python开发,尤其是结合树莓派的GPIO或其他硬件功能。
1. 通过APT包管理器安装(推荐)
sudo apt update
sudo apt install thonny
2. 使用Python PIP安装(获取最新版)
sudo apt install python3-pip # 确保pip已安装
pip3 install thonny --user # 用户级安装
启动方式:
~/.local/bin/thonny
2 启动
thonny
直接可以启动了。
六 摄像头安装
看这篇文章
树莓派4B+Ubuntu24.04 LTS 摄像头安装 保姆级教程
亲测对于树莓派4bubuntu22.04也可以用
总结
本文是树莓派4b的一些基础设置,有助于各位散修宝子,内容亲测有效。
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐
所有评论(0)