Ubuntu 环境配置备忘录

账号

新建有 root 权限的普通账户

BASH
# 用 root 账号操作
adduser <username>
usermod -aG sudo <username>  # 将用户添加到 sudo 组
# 配置免密码 sudo
visudo
# 文件末尾追加
<username> ALL=(ALL) NOPASSWD:ALL
点击展开查看更多

zsh

先装字体

BASH
# Mac 自带,无需安装
sudo apt install zsh
sudo chsh -s /usr/bin/zsh $USER

# 无需初始化配置,后续在 Powerlevel10k 后配置

# oh-my-zsh,一个 zsh 的配置框架
sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

# Powerlevel10k,一个 oh-my-zsh 的主题
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k

echo 'source ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k/powerlevel10k.zsh-theme' >>~/.zshrc

# 重启 Shell 进入配置
点击展开查看更多

插件

BASH
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

# 在 ~/.zshrc 中启用插件
plugins=(git sudo z zsh-autosuggestions zsh-syntax-highlighting)
点击展开查看更多

Vim

安装 nvim

MacOS

BASH
brew install neovim
# vim ~/.zshrc
alias vim="nvim"
点击展开查看更多

Ubuntu

BASH
curl -LO https://github.com/neovim/neovim/releases/latest/download/nvim-linux-x86_64.tar.gz
# 树莓派是 Arm
curl -LO https://github.com/neovim/neovim/releases/latest/download/nvim-linux-arm64.tar.gz

sudo rm -rf /opt/nvim
sudo tar -C /opt -xzf nvim-linux-x86_64.tar.gz

# vim ~/.zshrc
export PATH="$PATH:/opt/nvim-linux-x86_64/bin"
alias vim="nvim"

# sudo nvim
sudo ln -s /opt/nvim-linux-x86_64/bin/nvim /usr/local/bin/nvim
点击展开查看更多

LazyVim

BASH
# required
mv ~/.config/nvim{,.bak}

git clone https://github.com/LazyVim/starter ~/.config/nvim
rm -rf ~/.config/nvim/.git
vim  # 启动后会自动进行一系列下载安装
点击展开查看更多

其他命令行工具

bat:增强版 cat

BASH
# macOS
brew install bat
alias cat="bat -pp"

# Linux
sudo apt install bat
alias cat='batcat -pp'
alias bat='batcat'
点击展开查看更多

eza:增强版 ls

BASH
# macOS
brew install eza
# Linux
sudo apt install eza

alias ls='eza --color=always --icons'
alias ll='eza -la --color=always --icons --git'
alias la='eza -la --color=always --icons --git'
alias lt='eza --tree --color=always --icons'
alias tree='eza --tree --color=always --icons --level=3'
alias ltree='eza -Tla --color=always --icons --git --level=2 --git-repos'
alias bigtree='eza -Tla --total-size --sort=size --color=always --icons --level=2'
点击展开查看更多

ncdu:交互式磁盘空间分析,增强版 du

BASH
# macOS
brew install ncdu
# Linux
sudo apt install ncdu

cd /path/to/dir
ncdu  # 使用方向键浏览,按 d 删除选中项
点击展开查看更多

duf:美观的 df

BASH
# macOS
brew install duf
duf
点击展开查看更多

btop:增强版 top

BASH
brew install btop
点击展开查看更多

tldr:省去冗长的 man 文档

BASH
brew install tldr
# example
tldr tar
点击展开查看更多

SSH Key

客户端生成 SSH Key

BASH
# Windows PowerShell
ssh-keygen -t ed25519 -C "razer-wsl" -f $env:USERPROFILE\.ssh\id_ed25519_razer_wsl

# Ubuntu & MacOS
sh-keygen -t ed25519 -C "razer-wsl" -f ~/.ssh/id_ed25519_razer_wsl

cat ~/.ssh/id_ed25519_razer_wsl.pub
点击展开查看更多

Python

装个 uv 就完事儿了

BASH
curl -LsSf https://astral.sh/uv/install.sh | sh
点击展开查看更多

Python 使用 UV 进行环境管理

如果想随时启动一个 python 交互式视窗(REPL)可以 uv run python

Samba

树莓派配置 PLEX 服务器 & SMB

安装 plex server,官网下载 Arm64 安装包

BASH
sudo dpkg -i plexmediaserver_1.41.7.9823-59f304c16_arm64.deb
点击展开查看更多

安装配置 SMB

BASH
sudo apt install samba samba-common-bin

sudo mkdir -p /media/plex
sudo chown isumi:isumi /media/plex
sudo vim /etc/samba/smb.conf
点击展开查看更多

SMB 配置文件末尾追加,可以额外设置共享 home

PLAINTEXT
[homes]
   comment = Home Directories
   browseable = no

# By default, the home directories are exported read-only. Change the
# next parameter to 'no' if you want to be able to write to them.
   read only = no

# File creation mask is set to 0700 for security reasons. If you want to
# create files with group=rw permissions, set next parameter to 0775.
   create mask = 0775

# Directory creation mask is set to 0700 for security reasons. If you want to
# create dirs. with group=rw permissions, set next parameter to 0775.
   directory mask = 0775

# By default, \\server\username shares can be connected to by anyone
# with access to the samba server.
# The following parameter makes sure that only "username" can connect
# to \\server\username
# This might need tweaking when using external authentication schemes
   valid users = %S

[plex]
    comment = Plex Media
    path = /media/plex
    browseable = yes
    writeable = yes
    only guest = no
    create mask = 0777
    directory mask = 0777
    public = no
    valid users = isumi
点击展开查看更多

建立 SMB 账号,启动 SMB 服务

BASH
# isumi 是 Linux 已有的用户名
sudo smbpasswd -a isumi
sudo systemctl restart smbd
sudo systemctl enable smbd
点击展开查看更多

访问 \\IP\plex 即可

版权声明

作者: Aspi-Rin

链接: https://blog.aspi-rin.top/posts/ubuntu-%E7%8E%AF%E5%A2%83%E9%85%8D%E7%BD%AE%E5%A4%87%E5%BF%98%E5%BD%95/

许可证: CC BY 4.0

This work is licensed under a Creative Commons Attribution 4.0 International License. Please attribute the source.

开始搜索

输入关键词搜索文章内容

↑↓
ESC
⌘K 快捷键