Ubuntu 基础设置

Ubuntu 基础设置,包括终端、Vim、程序快捷方式、Git等。

主题设置

  1. 修改终端颜色
  2. 修改图标大小
  3. 修改壁纸

终端设置

终端路径名称太长

修改配置文件 vim ~/.bashrc 中小写 w 为大写 W,source ~/.bashrc

1
2
3
4
5
6
7
if [ "$color_prompt" = yes ]; then
# PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\W\[\033[00m\]\$ '
else
# PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\W\$ '
fi

Vim 设置

显示行号

  1. 临时显示行号 :set number 或者 :set nu
  2. 永久显示行号
    1. 查找配置文件 find / -name vimrc 2>&1 | grep -v "Permission denied"
    2. 编辑 sudo vim /etc/vimrc,添加 set number

程序设置

软链接

1
ln -s /path/to/soure/file /path/to/target/file

桌面快捷方式

  1. 打开 application 文件夹
1
2
cd /usr/share/applications
cd ~/.local/share/applications
  1. 创建应用快捷方式 touch myapp.desktop
1
2
3
4
5
6
7
8
[Desktop Entry]
Encoding=UTF-8
Name=myapp
Comment=This is my application
Exec=/path/to/myapp
Icon=/path/to/myapp_image.png
Terminal=false
Type=Application
  1. 增加权限 chmod +x myapp.desktop,注意执行时如果出现闪退,则在终端中直接执行 /path/to/myapp 查看出错信息并修复

配置 Git

安装

安装 Git

1
2
sudo apt-get update
sudo apt-get install git

配置 Git 用户名和邮箱

1
2
3
git config --global user.name git_name
git config --global user.email git_email@email.com
git config --list

生成 SSH 密钥,设置默认

1
ssh-keygen -t rsa -C git_email@email.com

提示信息

1
2
Your identification has been saved in ~/.ssh/id_rsa
Your public key has been saved in ~/.ssh/id_rsa.pub

查看公钥内容并复制到 SSH keys 中,在 Github -> Setting -> SSH and GPG keys -> new SSH key 新建key并输入 title 和 key 即可

1
cat ~/.ssh/id_rsa.pub

检查是否设置成功 Testing your SSH connection,对比公钥指纹是否一致

1
ssh -T git@github.com

VSCode

拉取项目 git clone https://github.com/xxxxx.git/,首次可能报错

1
fatal: unable to access 'https://github.com/xxxxx.git/': gnutls_handshake() failed: The TLS connection was non-properly terminated.

设置代理或 gnutls 包原因 Ubuntu error: gnutls_handshake(),后者可采用 openssl 编译或更换更为稳定的代理

1
2
git config --global http.https://github.com.proxy http://127.0.0.1:7890
git config --global https.https://github.com.proxy https://127.0.0.1:7890

克隆私有仓库可能报错,参考 Stackoverflow Message

1
2
remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.

apt 添加代理

apt 设置代理

1
2
3
4
5
6
7
8
9
10
11
12
13
# 清除缓存
sudo apt clean
# 临时添加代理
sudo apt -o Acquire::http::Proxy="http://127.0.0.1:7890" -o Acquire::https::Proxy="https://127.0.0.1:7890" update
# 添加文件 二选一
sudo vim /etc/apt/apt.conf
sudo vim /etc/apt/apt.conf.d/proxy.conf
# 添加代理
Acquire::http::Proxy "http://127.0.0.1:7890/";
Acquire::https::Proxy "https://127.0.0.1:7890/";
# 添加用户名和密码
Acquire::http::Proxy "http://username:password@proxy-IP-address:proxyport";
Acquire::https::Proxy "http://username:password@proxy-IP-address:proxyport";

终端设置代理 Blog-Ubuntu 配置clash的四种方式

1
2
3
4
5
6
7
8
# 在终端使用代理
export http_proxy=http://127.0.0.1:7890
export https_proxy=http://127.0.0.1:7890
# 测试代理可用
curl -i google.com
# 在终端取消代理
unset http_proxy
unset https_proxy

设置输入法

在Linux系统上,常见的输入法框架(Keyboard input method system)有三种:

  • IBus(Intelligent Input Bus)
  • Fcitx(FlexibleInput Method Framework)
  • XIM(X Input Method)

选择 Setting > System > Region & Language > System 中选择 Manage Installed Language > Language > Keyboard input method system 选项,可以看到在Ubuntu 24.02 LTS系统中,已安装 IBus 和 XIM 输入法框架,默认为 IBus 框架.

选择 Setting > Keyboard > Input Sources 选择中文输入法为 Chinese(Intelligent Pinyin).

选择 Chinese(Intelligent Pinyin) > Preference 修改智能输入选项.

  • Pinyin mode 面板中打开 Cloud Input Option > Enable Cloud Input > Baidu
  • Dictionary Option 面板中选择需要导入的字典
0%