1. 安装
Termux 是运行在 Android 上的 terminal。不需要root,运行于内部存储(不在SD卡上)。
自带了一个包管理器 pkg
,可以安装许多现代化的开发和系统维护工具。比如:
- neovim
- tmux
- zsh
- clang
- gcc
- python
- weechat
- irssi
注意:在Google和F-Droid上发布的安装包由于签名不同,并不能相互替换,尤其是在匹配其插件(如Termux-API)时,可能造成意外的错误。
插件列表:
-
API: 用于调用安卓的原生功能,如拨打电话、拍照、GPS定位信息等
-
Termux:API
Access Android and Chrome hardware features.
-
Termux:Boot
Run script(s) when your device boots.
-
Termux:Float
Run Termux in a floating window.
-
Termux:Styling
Have color schemes and powerline-ready fonts customize the appearance of the Termux terminal.
-
Termux:Tasker
An easy way to call Termux executables from Tasker and compatible apps.
-
Termux:Widget
Start small scriptlets from the home screen.
2. 更新源
# The termux repository mirror from TUNA:
deb https://mirrors.tuna.tsinghua.edu.cn/termux/termux-packages-24 stable main
# The termux repository mirror from TUNA:
deb https://mirrors.tuna.tsinghua.edu.cn/termux/science-packages-24 science stable
# The termux repository mirror from TUNA:
deb https://mirrors.tuna.tsinghua.edu.cn/termux/game-packages-24 games stable
然后执行 pkg update
,注意,提示更新系统命令时,选择 n
,否则会造成系统不稳定!
推荐安装以下软件:
pkg install openssh htop tsu proot git nano neofetch python
- tsu:切换账户(root)
- proot:无root权限执行需要root的命令
- neofetch:查看系统信息
3. 系统配置
termux-setup-storage # 获取对sdcard的读取权限
pkg install termux-services
pkg install termux-api
termux-wake-lock # 息屏时保持Termux后台运行(否则cpu严重降速甚至ssh卡断)
4. 配置ssh
pkg install openssh
安装好之后,我们需要手工启动: sshd
需要指出的是, sshd 监听的是8022端口而不是22号端口,因此可以使用下面命令来验证ssh服务是否开启。
ssh localhost -p 8022
若要查看sshd的日志,则可以在Termux上执行
logcat -s ‘syslog:*‘
为了方便,我们可以配置一下ssh client的配置文件,将下面内容加入到 ~/.ssh/config
文件中:
Host termux
User u0_a171
HostName 192.168.31.145
Port 8022
这样只需要执行 ssh termux 就能登陆termx了。
5. Python库的安装
-
lxml:
pkg install libxml2 libxslt && pip install lxml
-
Pillow:
pkg install libjpeg-turbo && pip install pillow
-
numpy:
pip install numpy
-
pandas:
最新版本失败,但
pip install pandas==1.0.5
成功
6. Termux:API
In Google Play Store, besides installing the Termux app, also install "Termux:API" app. This solves the hanging issue described below on Android 7.
To use Termux:API you also need to install the termux-api package.
pkg install termux-api
Current API implementations:
-
termux-battery-status
Get the status of the device battery.
-
termux-brightness
Set the screen brightness between 0 and 255.
-
termux-call-log
List call log history.
-
termux-camera-info
Get information about device camera(s).
-
termux-camera-photo
Take a photo and save it to a file in JPEG format.
-
termux-clipboard-get
Get the system clipboard text.
-
termux-clipboard-set
Set the system clipboard text.
-
termux-contact-list
List all contacts.
-
termux-dialog
Show a text entry dialog.
-
termux-download
Download a resource using the system download manager.
-
termux-fingerprint
Use fingerprint sensor on device to check for authentication.
-
termux-infrared-frequencies
Query the infrared transmitter‘s supported carrier frequencies.
-
termux-infrared-transmit
Transmit an infrared pattern.
-
termux-job-scheduler
Schedule a Termux script to run later, or periodically.
-
termux-location
Get the device location.
-
termux-media-player
Play media files.
-
termux-media-scan
MediaScanner interface, make file changes visible to Android Gallery
-
termux-microphone-record
Recording using microphone on your device.
-
termux-notification
Display a system notification.
-
termux-notification-remove
Remove a notification previously shown with termux-notification --id.
-
termux-sensor
Get information about types of sensors as well as live data.
-
termux-share
Share a file specified as argument or the text received on stdin.
-
termux-sms-list
List SMS messages.
-
termux-sms-send
Send a SMS message to the specified recipient number(s).
-
termux-storage-get
Request a file from the system and output it to the specified file.
-
termux-telephony-call
Call a telephony number.
-
termux-telephony-cellinfo
Get information about all observed cell information from all radios on the device including the primary and neighboring cells.
-
termux-telephony-deviceinfo
Get information about the telephony device.
-
termux-toast
Show a transient popup notification.
-
termux-torch
Toggle LED Torch on device.
-
termux-tts-engines
Get information about the available text-to-speech engines.
-
termux-tts-speak
Speak text with a system text-to-speech engine.
-
termux-usb
List or access USB devices.
-
termux-vibrate
Vibrate the device.
-
termux-volume
Change volume of audio stream.
-
termux-wallpaper
Change wallpaper on your device.
-
termux-wifi-connectioninfo
Get information about the current wifi connection.
-
termux-wifi-enable
Toggle Wi-Fi On/Off.
-
termux-wifi-scaninfo
Get information about the last wifi scan.