Ubuntu Config

2023/09/24

Tags: ubuntu

以下配置都是在 Ubuntu 22.04 系统配置

配置中文输入法

  1. Open Settings, go to Region & Language -> Manage Installed Languages -> Install / Remove languages.
  2. Select Chinese (Simplified). Make sure Keyboard Input method system has Ibus selected. Apply.
  3. Reboot
  4. Log back in, reopen Settings, go to Keyboard.
  5. Click on the “+” sign under Input sources.
  6. Select Chinese (China) and then Chinese (Intelligent Pinyin).

ubuntu-22-04-chinese-simplified-pinyin-input-support

修正简体中文显示为异体(日文)字形

ubuntu/linux对中文支持的不太好, 在选择汉字字体时, 优先选择的是日文或者韩文, 需要手动调整优先级后重启操作系统解决

root权限编辑 /etc/fonts/conf.avail/64-language-selector-prefer.conf 配置文件

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
        <alias>
                <family>sans-serif</family>
                <prefer>
+                       <family>Noto Sans CJK SC</family>
                        <family>Noto Sans CJK JP</family>
                        <family>Noto Sans CJK KR</family>
-                       <family>Noto Sans CJK SC</family>
                        <family>Noto Sans CJK TC</family>
                        <family>Noto Sans CJK HK</family>
                        <family>Lohit Devanagari</family>
                        <family>Noto Sans Sinhala</family>
                </prefer>
        </alias>
        <alias>
                <family>serif</family>
                <prefer>
+                       <family>Noto Serif CJK SC</family>
                        <family>Noto Serif CJK JP</family>
                        <family>Noto Serif CJK KR</family>
-                       <family>Noto Serif CJK SC</family>
                        <family>Noto Serif CJK TC</family>
                        <family>Lohit Devanagari</family>
                        <family>Noto Serif Sinhala</family>
                </prefer>
        </alias>
        <alias>
                <family>monospace</family>
                <prefer>
+                       <family>Noto Sans Mono CJK SC</family>
                        <family>Noto Sans Mono CJK JP</family>
                        <family>Noto Sans Mono CJK KR</family>
-                       <family>Noto Sans Mono CJK SC</family>
                        <family>Noto Sans Mono CJK TC</family>
                        <family>Noto Sans Mono CJK HK</family>
                </prefer>
        </alias>
</fontconfig>

apt

https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/

sudo su -

cat <<EOF > /etc/apt/sources.list
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse

deb http://security.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse
deb-src http://security.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse

# 预发布软件源,不建议启用
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse
EOF

apt update -y

使用X11替换Wayland

Wayland目前在我的AMD 5700U小机器上还是不太好用, 鼠标指针会有卡顿

编辑 /etc/gdm3/custom.conf

- #WaylandEnable=false
+ WaylandEnable=false

合上盖子不暂停系统(笔记本)

Make Ubuntu Not Go in Suspend When Laptop Lid is Closed

如果是在笔记本上安装的, 那么这个设置可以防止合上盖子LidSuspend系统

编辑/etc/systemd/logind.conf文件

- #HandleLidSwitch=suspend
+ HandleLidSwitch=ignore
- #HandleLidSwitchExternalPower=suspend
+ HandleLidSwitchExternalPower=ignore
- #HandleLidSwitchDocked=ignore
+ HandleLidSwitchDocked=ignore

然后重启 systemd-logind 生效

systemctl restart systemd-logind

安装 oh my zsh

sudo apt install zsh curl -y
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

ohmyz.sh

安装 golang

下载并解压到 /usr/local/go目录下

sudo apt install wget -y
wget https://go.dev/dl/go1.21.1.linux-amd64.tar.gz
sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf go1.21.1.linux-amd64.tar.gz

修改所有user和所有shellPATH环境变量, 下面文件都添加一行 export PATH=$PATH:/usr/local/go/bin

/etc/zsh/zshenv
/etc/profile
/etc/bash.bashrc

新开一个shell会话验证

➜  ~ go version
go version go1.21.1 linux/amd64

Download and install

安装 hugo

sudo apt install build-essential -y
CGO_ENABLED=1 go install -tags extended github.com/gohugoio/hugo@latest

设置当前用户zshPATH环境变量

vim ~/.zshrc

+ export PATH=${PATH}:`go env GOPATH`/bin

新开一个zsh shell会话验证

➜  ~ hugo version
hugo v0.118.2+extended linux/amd64 BuildDate=unknown

安装 openssh-server

sudo apt install openssh-server

sudo vim /etc/ssh/sshd_config

- #PermitRootLogin prohibit-password
+ PermitRootLogin yes
sudo systemctl restart ssh

安装 gnome 插件

需要先安装有GNOME Shell extension

sudo apt install gnome-shell-extension-manager

所有网卡都禁用ipv6

修改/etc/sysctl.conf

+ net.ipv6.conf.all.disable_ipv6 = 1

然后执行sysctl -p加载新的配置生效

修改/etc/default/grub

- GRUB_CMDLINE_LINUX="..."
+ GRUB_CMDLINE_LINUX="... ipv6.disable=1"

然后执行update-grub更新GRUB, 这种指定传递给内核命令行的参数的方式需要重启系统之后才能生效

安装VLC媒体播放器

https://www.videolan.org/vlc/download-ubuntu.html

sudo apt install vlc

快捷键

快捷键功能
v切换字幕

安装 docker

https://docs.docker.com/engine/install/ubuntu/ https://github.com/docker/docker-install

curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh ./get-docker.sh

安装virt-manager

sudo apt install virt-manager -y

设置所有sudo组下的用户执行sudo命令不需要密码

EDITOR=vim visudo

# Allow members of group sudo to execute any command
- %sudo   ALL=(ALL:ALL) ALL
+ %sudo   ALL=(ALL:ALL) NOPASSWD:ALL

删除用户密码

危险操作, 具有sudo权限的普通用户就更是危险操作了, 不过自己在家用时, 每次解锁或登录不用输入一长串密码真的很方便!!!, 这样就可以把Screen Blank的时间调短一点了😄

passwd有一个-d参数

# passwd -h | grep -e "-d"
  -d, --delete                  delete the password for the named account

删除某个账户的密码

sudo passwd -d {username}