richardmyu / blog

个人(issues)博客
https://github.com/richardmyu/blog/issues
MIT License
0 stars 0 forks source link

ubuntu(20.04)安装及其他配置记录 #28

Open richardmyu opened 2 years ago

richardmyu commented 2 years ago

1.下载和刻制U盘

官网下载 Ubuntu

中文官网 英文官文

制作U盘

这部分网上教程很多,我选的是 Universal USB Installer,安装起来很简单。

2.分区

分区这一块也不是很懂,只是简单的分了 / 50G、swap 16G、/boot 2G、/home 剩下全部。

3.驱动

装了驱动,但是开启双屏后,鼠标会在标题栏附近闪烁,后面更是发生了合盖后无法唤醒等问题,不能肯定说都是驱动带来的,但这些问题确实是安装驱动之后才有的。所以这次重装系统,就不准备安装驱动了,把需要双屏完成的工作,留给 win11 来完成。

4.换源以及更新

这些教程也很多,也不多说了。


下面主要说说 ubuntu 系统下,安装的应用程序的一些问题和细节。

richardmyu commented 2 years ago

5.安装 nvm

昨天使用 curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash 的时候,报错为:

curl: (60) SSL certificate problem: unable to get local issuer certificate

今天再试,报错为:

curl: (7) Failed to connect to raw.githubusercontent.com port 443: 拒绝连接

使用 raw.githubusercontent.com,报 curl: (7) 类错误,而使用 github.com,则报 curl: (60) 类错误;而使用国内的 gitee,丝毫没有问题。


最后还是靠手动下载 install.sh,在 ~ 目录下创建 .nvm 目录,然后放入脚本并运行:

cd ~

mkdir .nvm

cd .nvm

bash install.sh

sudo vim ~/.zshrc  # or .nashrc or .profile

粘贴以下代码:

export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm

注意是两行的

然后:

source ~/.zshrc
nvm -v

若能查到正确版本号,就安装完成。后面就是要修改源了:

# nvm 源
vim ~/.nvm/nvm.sh
# 搜索 NVM_NODEJS_ORG_MIRROR,大概在 1915 行
# ${NVM_NODEJS_ORG_MIRROR:-https://nodejs.org/dist}" ;;
# to
# ${NVM_NODEJS_ORG_MIRROR:-https://npm.taobao.org/mirrors/node/i}" ;;
source ~/.nvm/nvm.sh

# npm 源
npm config set registry https://registry.npm.taobao.org/

更新

第二次安装(新系统),在我要编辑 .zshrc 文件的时候,发现里面有:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

这时候,不用手动添加,再更新一下 .zshrc,就可以查看 nvm 版本信息了,即安装成功了。


nvm 官网提供安装的命令:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash

wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash

-o 我懂,但不明白 -o- 是什么意思,查了一下,也没找到答案。

参考: nvm-sh/nvm Ubuntu nvm安装笔记

richardmyu commented 2 years ago

6.Typora

使用 Ubuntu Software 安装 Typora 后,再安装 pandoc,怎么都无法使用 pandoc;查看官网以后,尝试使用命令行安装,结果是可以使用 pandoc 插件。

wget -qO - https://typora.io/linux/public-key.asc | sudo apt-key add -

# add Typora's repository
# 末尾 ./ 不要忽略或遗漏
sudo add-apt-repository 'deb https://typora.io/linux ./'
sudo apt-get update

# install Typora
sudo apt install typora 

Install Typora on Linux

richardmyu commented 2 years ago

7.oh-my-zsh

首先安装出现很大的问题,按照官方的方法,不管是开启还是关闭代理:

curl: (7) Failed to connect to raw.githubusercontent.com port 443: 拒绝连接

可以从官网下载 /tools/install/home/username/ 下,然后运行 ./install.sh,然后自动克隆仓库,然后出现安装成功的标志。

当然还可以直接克隆:

# 根据实际情况,调整仓库 API
git clone git@hub.fastgit.org:ohmyzsh/ohmyzsh.git ~/.oh-my-zsh
cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc

# 将 zsh 设置为系统默认 shell
sudo chsh -s /bin/zsh

# 查看
echo $SHELL

设置 shell,我的电脑需要重启,才能启用。


我觉得最有用的插件大概就是 zsh-autosuggestionszsh-syntax-highlighting了:

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

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

然后修改 .zshrc

plugins=( 
        git 
        zsh-autosuggestions
        zsh-syntax-highlighting 
)

再让配置文件生效,source ~/.zshrc


热键绑定

bindkey '\e[1;3D' backward-word       # ALT+左键:向后跳一个单词
bindkey '\e[1;3C' forward-word        # ALT+右键:前跳一个单词
bindkey '\e[1;3A' beginning-of-line   # ALT+上键:跳到行首
bindkey '\e[1;3B' end-of-line         # ALT+下键:调到行尾
richardmyu commented 2 years ago

8.进入睡眠状态无法唤醒

上一次装系统的时候,驱动正常,可以改,没有其他毛病(也没出现和盖后无法唤醒);

第二次装系统的时候,驱动是手动,无法在系统中改驱动,后来使用命令安装驱动,这样可以使用第二屏看也页面了,没想到带来了副作用,昨晚合上显示屏,没有进入睡眠状态,把电池耗完了。今天充电完成了,发现可以进入睡眠状态,但是进入睡眠状态,就无法唤醒,屏幕一直是黑的,左上角一个光标一直闪烁,只能通过电源键强制关机,然后开机使用。

1.检查是否安装了laptop-mode-tools 工具包:

$ dpkg -l | grep laptop-mode-tools

如果执行命令无结果输出,表示未安装(如果已安装,忽略第2步)。

2.安装 laptop-mode-tools:

sudo apt-get install laptop-mode-tools

# 查看
dpkg -l | grep laptop-mode-tools
# ii laptop-mode-tools   x.xx-ubuntu
# all                 Tools for Power Savings based on
# battery/AC status

3.判断 Laptop 是否启用了 laptop_mode 模式

如果显示结果为 0,则表示未启动,如果为非 0 的数字则表示启动了。

cat /proc/sys/vm/laptop_mode
# 0

4.启动 laptop_mode

修改配置文件 /etc/default/acpi-support,更改:

ENABLE_LAPTOP_MODE=true

直接在终端中输入 sudo laptop_mode start。启动了 laptop_mode 之后,基本上就不会遇到无法唤醒的情况了。

有些用户在 acpi-support 中并未找到 ENABLE_LAPTOP_MODE=true 被注释的项。文件最后一行有提示:

# Note: to enable "laptop mode: (to spin down your hard drive for longer
# periods of time), install the laptop-mode-tools package and configure
# it in /etc/laptop-mode/laptop-mode.conf.

/etc/laptop-mode/laptop-mode.conf 中进行配置:

#
# Enable laptop mode when on bettery power.
#
ENABLE_LAPTOP_MODE_ON_BATTERY=1

#
# Enable laptop mode when on AC power.
#
ENABLE_LAPTOP_MODE_ON_AC=1

#
# Enable laptop mode when the laptop's lid is closed, even when we're on AC
# power? (ACPI-ONLY).
#
ENABLE_LAPTOP_MODE_WHEN_LID_CLOSED=1

启动 laptop_mode 并查看:

sudo laptop_mode start
# Laptop mode
# enabled, active [unchanged]

到此基本完成。


参考:

解决ubuntu合盖后无法唤醒

richardmyu commented 2 years ago

9.clean...files...blocks

安装了一下 python,分别试了一下 2.x 和 3.x 版本,使用 autoremove 删除包,出现了问题;首先是浏览器异常,重启后,浏览器没了,再看一下应用程序列表,发现少了好几个;然后准备重启看看,然后出现一下信息:

/dev/nvme0n1p2: clean, xxxxxx/xxxxxxxx files, xxxxxxx/xxxxxxxxx blocks

按照参考 1 操作到 init 3 进入文本模式,就无法操作了。

Failed to open initctl fifo: xxxx
Failed to talk to daemon.

参考:

[1]: ubuntu开机卡在/dev/sda3: clean ... files,... blocks不动的解决方案 [2]: ubuntu启动错误: /dev/sda1 xxxx clean, xxxx/xxxx files, xxxx/xxxx blocks

richardmyu commented 2 years ago

10.“门” 等字的异常显示

因为 Noto Sans CJK 中包含日文韩文,而日文的排序中文的前面。

JP KR SC TC

鉴于系统我选择的是语言是英语,所以只调整了排序。在 /etc/fonts/conf.d/64-language-selector-prefer.conf 调整顺序就行。

SC TC JP KR

然后更新字体缓存即可生效:

# fc-cache -fv

执行以下命令检查,如果出现 NotoSansCJK-Regular.ttc: "Noto Sans CJK SC" "Regular" 则表示设置成功:

# fc-match -s | grep 'Noto Sans CJK'

参考Localization (简体中文)/Simplified Chinese (简体中文)

richardmyu commented 2 years ago

11.搭建 c 开发环境

1.安装 vscode 并安装 c/c++ 插件

2.终端安装 gcc/g++ 环境

sudo apt install build-essential

参考:

在Ubuntu下搭建C/C++编程环境

richardmyu commented 2 years ago

12.搭建 python 环境

前提:系统默认 python v3.8.10,没有 python2.x,且不打算安装 python2.x。

不要随便删除 python,不要随便删除 python,不要随便删除 python!

1.安装 pycharm

pycharm 官网

选择好版本,下载完成后,会在 Downloads 得到 pycharm-community-202x.x.x.tar.gz 的文件:

# 解压
cd ~/
tar -xvzf Downloads/pycharm-community-202x.x.x.tar.gz -C ./Software

# 启动
cd ./Software/pycharm-community-202x.x.3/bin
sh ./pycharm.sh

安装好以后,是通过 sh ./pycharm.sh 启动的,所以需要一个快捷方式。

添加 pycharm 快捷启动方式:

cd /usr/share/applications

sudo touch pycharm.desktop
sudo vim pycharm.desktop

pycharm.desktop

[Desktop Entry]
Type = Application
Name = Pycharm
Exec = /home/xx/xx/pycharm-community-2021.2.3/bin/pycharm.sh
Icon = /home/xx/xx/pycharm-community-2021.2.3/bin/pycharm.png
Terminal = false # 是否在终端打开
Categories = Pycharm

2.安装 pip 并换源

sudo apt install python3-pip

cd ~
mkdir .pip
cd .pip
touch pip.conf
vim pip.conf

pip.conf

[global]
timeout = 5000
index-url = https://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host = mirrors.aliyun.com

参考:

【环境配置】ubuntu 配置 python 开发环境 在Ubuntu20.04中搭建Python开发环境

richardmyu commented 2 years ago

13.dask-to-dash

安装了 dask-to-dash 后,有一定的概率出现原 dock 与当前 dock 并存。

sudo apt remove gnome-shell-extension-ubuntu-dock

# 实际一共删除了三个包
# gnome-shell-extension-ubuntu-dock
# ubuntu-desltop
# ubuntu-desktop-minimal

不知道会有怎样的副作用,先记录着吧!

richardmyu commented 2 years ago

14.VS Code

从 snap 安装的 VS Code 会出现无法切换中文的情况。

有人说官网下载的没问题,有的说也有问题,我决定试一试。

官网无法直接下载 VS Code,需要修改下载链接的域名:

# 官网的下载地址
https://az764295.vo.msecnd.net/stable/3a6960b964327f0e3882ce18fcebd07ed191b316/code_1.62.2-1636665017_amd64.deb

# 修改: 将 az764295.vo.msecnd.net 替换 vscode.cdn.azure.cn
https://vscode.cdn.azure.cn/stable/3a6960b964327f0e3882ce18fcebd07ed191b316/code_1.62.2-1636665017_amd64.deb

先卸载 VS Code,不需要删除配置文件,然后使用 dpkg 安装:

sudo dpkg -i code_1.62.2-1636665017_amd64.deb

打开安装好的 VS Code,之前的配置可以用,中英文切换正常。

更多阅读:

unable to input chinese character #96041

richardmyu commented 2 years ago

15.exa

exa 取代 ls,不是那花里胡哨的颜色,主要是 --tree-lR 好看多了。

按照文章 2 安装好 rust 环境和 cargo,然后使用 cargo 安装 exa,有问题:

error: failed to fetch `https://github.com/rust-lang/crates.io-index`

Caused by:
  network failure seems to have happened
  if a proxy or similar is necessary `net.git-fetch-with-cli` may help here
  https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli

Caused by:
  [7] Couldn't connect to server (Failed to connect to 127.0.0.1 port 1181 after 0 ms: Connection refused); class=Net (12)

不用细看,十有八九换源就可以解决 :sob:


1.exa(github) 2.How to Install Rust and Cargo on Ubuntu and Other Linux Distributions 3.Rust Crates 源使用帮助