目录
- 前言
- 1. 安装
- 2. 命令
- 3. 保持后台运行
- 4. 使用前准备
- 5. 使用设置
- 6. 终端配置与美化
- 7. 安装容器,这里是Debian
- 8. 配置远程桌面(两种方式选一种)
- 9. 汉化
- 10. 在Termux安装MongoDB
前言
这篇文章是自己摸索玩Termux总结出来的,适用自己的手机,不知道换个手机还合不合适,主要是涉及东西较多,为了方便自己再次查看,也提供给广大网友参考,内容基本都来自于各博主发布的文章,如有侵权,请告知,立刻删除!
1. 安装
2. 命令
pkg命令
pkg search <query> # 搜索包
pkg install <package> # 安装包
pkg uninstall <package> # 卸载包
pkg reinstall <package> # 重新安装包
pkg update # 更新源
pkg upgrade # 升级软件包
pkg list-all # 列出可供安装的所有包
pkg list-installed # 列出已经安装的包
pkg show <package> # 显示某个包的详细信息
pkg files <package> # 显示某个包的相关文件夹路径
dpkg命令
dpkg -i ./package.deb # 安装 .deb 包
dpkg --remove [package name] # 卸载软件包dpkg -l # 查看已安装的包man dpkg # 查看详细文档
3. 保持后台运行
- 开启唤醒锁
termux-wake-lock #开启唤醒锁
termux-wake-unlock #关闭唤醒
建议将唤醒锁的开启写入开机自启服务,以免自己忘记:
echo 'termux-wake-lock &' >>$PREFIX/etc/termux-login.sh
- 关闭省电策略允许后台运行
关闭省电策略和允许后台运行的方式手机型号不同方法也不同,这里就不不细说了,根据自己手机来就好。
4. 使用前准备
- 更换国内源
termux-change-repo
方向键选择,空格键选中,这里一般情况下选清华源就好:
找带这个字符串的:mirrors.tuna.tsinghua.edu.cn/
然后更新软件
pkg upgrade -y
此处有坑,第一次执行完pkg upgrade后,软件源会自动换回官方源,,,所以,更新完再执行一次换源操作吧,第二次界面会有点稍稍不同,网络没其他问题的话还是选择清华源就好
- 获取手机存储权限
termux-setup-storage
可建立软链接
ln -s $HOME/storage [文件或文件夹路径] #建立软链接
rm -rf [链接文件或文件夹路径]
注意,在删除软链接时,路径结尾一定不能带/,不然删除的就是原文件!!!
- 基础软件安装
pkg install vim nano git wget curl -y
5. 使用设置
- 启动问候语
编辑$PREFIX/etc/motd
vim $PREFIX/etc/motd
一个好看的图像:
_____
|_ _|__ _ __ _ __ ___ _ ___ __
| |/ _ \ '__| '_ ` _ \| | | \ \/ /
| | __/ | | | | | | | |_| |> <
|_|\___|_| |_| |_| |_|\___</_/\_\
Put wings on your dreams!
- 界面设置
通过编辑~/.termux/termux.properties
文件进行基础设置
nano ~/.termux/termux.properties
推荐
# 设置底部导航栏,DRAWER是抽屉菜单,侧面长按老是出现不出来
extra-keys = [['ESC','DRAWER','/','HOME','UP','END','PGUP'], \
['TAB','CTRL','ALT','LEFT','DOWN','RIGHT','PGDN']]
# 曲面屏设置左右留空,方便复制
terminal-margin-horizontal=3
以上内容参考了易冰亦寒的【Termux——安装配置】详细内容自行查看
6. 终端配置与美化
- zsh安装
- 安装zsh
# 更新软件源
apt update && sudo apt upgrade -y
# 安装 zsh git curl
apt install zsh nano git curl -y
- 将zsh设置成默认shell,重启终端
chsh -s /bin/zsh
或者
chsh -s $(which zsh)
- Oh-my-zsh安装
- zsh是shell脚本,oh-my-zsh是zsh的配置,安装Oh-my-zsh
sh -c "$(curl -fsSL https://install.ohmyz.sh/)"
或者:
sh -c "$(wget -O- https://install.ohmyz.sh/)"
下载后,会出现 ~/.zshrc
文件,类似 ~/.bashrc
文件,后面设置主题会用到
- 安装语法高亮
zsh-syntax-highlighting
和历史命令建议zsh-autosuggestions
插件
#zsh-autosuggestions 命令行命令键入时的历史命令建议
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
#zsh-syntax-highlighting 命令行语法高亮插件
git clone https://gitee.com/Annihilater/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
可以在```~/.oh-my-zsh/custom/plugins``目录可以看到下载好的两个主题
- powerlevel10k主题安装
git clone https://github.com/romkatv/powerlevel10k.git $ZSH_CUSTOM/themes/powerlevel10k
下载完,可以看到~/.oh-my-zsh/custom/themes
目录多了powerlevel10k
文件夹
- 修改
~/.zshrc
配置
nano ~/.zshrc
编辑 ~/.zshrc
设置ZSH_THEME
,使主题生效
# 使用powerlevel10k主题
ZSH_THEME="powerlevel10k/powerlevel10k"
oh-my-zsh也集成了大量主题,修改ZSH_THEME
值为相应名字即可
所有主题的效果见:Themes · robbyrussell/oh-my-zsh Wiki
在~/.zshrc中的plugins中增加内容,使插件生效
# 插件
plugins=(
git
zsh-autosuggestions
zsh-syntax-highlighting
z
)
增加配置
# 启动错误命令自动更正
ENABLE_CORRECTION="true"# 在命令执行的过程中,使用小红点进行提示COMPLETION_WAITING_DOTS="true"
~/.zshrc 最终文件内容如下:
export ZSH="$HOME/.oh-my-zsh"
# 启动错误命令自动更正ENABLE_CORRECTION="true"# 在命令执行的过程中,使用小红点进行提示COMPLETION_WAITING_DOTS="true"# 主题ZSH_THEME="powerlevel10k/powerlevel10k"# 插件plugins=( git zsh-autosuggestions zsh-syntax-highlighting z extract )source $ZSH/oh-my-zsh.sh
- 使之生效
source ~/.zshrc
若是用的是powerlevel10k主题,会启动主题配置,根据提示选择喜好
参考文章:nomoremorphine的【Linux终端配置与美化(zsh+oh-my-zsh+powerlevel10k+terminator终端)】
7. 安装容器,这里是Debian
- 安装proot 和proot-distro
pkg install proot proot-distro -y
安装完成后执行proot-distro list
可以列出能proot安装的Linux列表
- 安装Debian Linux (这里就要看您的网络了)
proot-distro install debian #利用官方的proot-distro安装Debian
- 进入Debian系统
proot-distro login debian
- Debian换源(此处是清华源)
编辑/etc/apt/sources.list
文件
nano /etc/apt/sources.list
注释或删除原有源,添加如下内容
Debian11:
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian-security/ bullseye-security main contrib non-free
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security/ bullseye-security main contrib non-free
Debian12:
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware
- 更新debian源
apt update && apt upgrade -y
- 安装neofetch(图形化界面需要)
apt install neofetch -y
安装完成后可以执行neofetch
检查安装情况
- 创建用户
安装sudo
apt install sudo -y
创建新用户 tom
adduser tom
然后设置两遍密码,一路回车
创建完成后,将新用户tom加入sudoers组里
nano /etc/sudoers
在rootALL=(ALL:ALL) ALL
下一行插入```tom ALL=(ALL:ALL) ALL``
然后ctrl 加 x , 按Y 回车退出保存,然后输入exit 退出debian系统
- 用 tom 用户重进入Debian系统,并精简安装xfce4桌面
- 用新用户进入Debian系统
proot-distro login debian --user tom
- 精简安装xfce4桌面
sudo apt update
sudo apt install xfdesktop4 xfwm4 xfce4-panel xfce4-settings thunar gvfs dbus-x11 xfce4-session xfce4-terminal -y
安装中会出现语言选择,选择more和other,处选择chinese
执行(可选项)
sudo apt install gpg ssh
gpg : GNU隐私保护————最低限度的公钥操作
ssh: 安全外壳客户端和服务器(元包)
8. 配置远程桌面(两种方式选一种)
- 利用Termux源的tigervnc进行远程桌面
- 打开 termux 安装 tigervnc
apt install x11-repo #安装X11源
apt install tigervnc xorg-xhost
- 设置vnc启动脚本
nano vnc
编辑vnc
vncserver -kill :1 #关掉上次未关的vnc,不写也可以!
vncserver -geometry 2560x1600 -listen tcp :1
注意这里的 -geometry 为分辨率,按照你的手机分辨率设置,而且这里的x不是*,例如某平板分辨率为2560x1600的
- 写入host
nano host
DISPLAY=:1 xhost +
- #编辑启动debian vnc的脚本
nano startdebianvnc
sh vnc
sh hostproot-distro login debian --user tom
输入 sh startdebianvnc
,执行进入到debian系统中会让你设置vnc的密码,设置即可
进入debian系统输入 DISPLAY=:1 xfce4-session
开启xfce桌面!!!!
- 远程连接
下载安装Vnc Viewer,Address中输入localhost:1
,而后点击CREATE,按提示输入密码,就看到xfce桌面
- 利用Debian源里的tigervnc进行远程桌面
进入Debian系统(在termux中执行proot-distro login debian --user tom
即可进入)
- 安装tigervnc
apt install tigervnc-common tigervnc-standalone-server -y
- 配置vnc启动脚本
tigervncserver -xstartup /usr/bin/xfce4-session -geometry 2560x1600 -depth 24 :0
- 配置关闭vnc脚本
nano kill
/usr/bin/vncserver -kill :0
开启vnc(输入密码)
sh vnc
打开Vnc Viewer,输入localhost:0和密码连接
然后输入sh kill
就可以关掉vnc了!!
详情查看:@a欢迎欢迎!的【在华为平板的Termux上安装Debian Linux图形化界面的详细教程,向生产力更近一步】
9. 汉化
这一种方法只在容器中适用,对termux不适用,termux上还没找到合适的方法
- 安装字体
sudo apt install fonts-wqy-zenhei
- 安装locales
sudo apt install locales
- 设置/etc/locale.gen
nano /etc/locale.gen
将zh-CN.UTF-8 UTF-8前的注释去掉,或者将其填入
- 设置/etc/locale.conf
nano /etc/locale.conf
# 写入
LANG=zh_CN.UTF-8
- 运行dpkg-reconfigure locales
sudo dpkg-reconfigure locales #注意要sudo 运行
往下翻找到zh-CN.UTF-8 UTF-8,填写编号,再选择zh-CN.UTF-8
- locale命令基本使用
查看已经安装的语言环境:locale -a
查看当前系统语言环境变量配置: locale - 临时改变语言环境
export LANG=C.UTF-8
- 永久改变当前用户语言环境编辑
~/.bashrc
, 在.bashrc文件末尾加入export LANG=zh_CN.utf8
即可,执行source ~/.bashrc
即可生效 - 经常出现退出容器重新进入时变回了英文,此时需要重新运行
source ~/.bashrc
,尚未找到好的解决办法
参考文章:1.@a欢迎欢迎!的【在Termux的Debian Linux中设置中文界面】
2.拿下这个山头的【Debian配置系统中文语言 - CSDN App】
10. 在Termux安装MongoDB
安装MongoDB找了不少帖子,试过各种方法,总还是报错,直到找到sunbcy的【Termux安装各种数据库&中间件【测试设备Xiaomi10已解锁】】,只需要两条命令即可
pkg i tur-repo -y
pkg i mongodb -y