乐趣区

关于ubuntu:Ubuntu配置

Ubuntu 配置

1. 终端环境

1.1. 换国内软件源

cd /etc/apt/
cp sources.list sources.list.backup

# 中科大的软件源绝对比拟全
sed -i 's/archive.ubuntu.com/mirrors.ustc.edu.cn/g' /etc/apt/sources.list

# 检查一下源信息是不是来自 ustc.mirror
apt update
apt upgrade

1.2. 装置必要工具

apt install git
apt install curl
apt install wget

1.3. 创立罕用文件夹

mkdir Config Projects Scripts Settings

1.4. 装置 ZSH 和 OMZ

apt install zsh
rm .bashrc

# 网络不佳或者梯子倒了,能够抉择 gitee 的国内镜像
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
(wget "https://gitee.com/mirrors/oh-my-zsh/raw/master/tools/install.sh")

# 755 权限示意:rwx r-x r-x
chmod 755 install.sh
./install.sh

# 装置必要的 zsh 插件
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

# 配置.zshrc
touoch .zshenv
vim .zshrc
# Path to oh-my-zsh
export ZSH=$HOME/.oh-my-zsh

# Global variables
ZSH_THEME='ys'

# Load plugins
plugins=(z git sudo extract zsh-autosuggestions zsh-syntax-highlighting)
source $ZSH/oh-my-zsh.sh

# Alias for commands
alias lsa='ls -a'
alias cls='clear'
alias src='source'

alias cg='cargo'
alias py='python'
alias dk='docker'

# Load environments
source ~/.zshenv

1.4. 解决中文乱码

apt install language-pack-zh-hans

# Set the environment varibale
touch .zshenv
cat "export LANG="zh_CN.UTF-8"" >> .zshenv
source .zshenv

2. 开发环境

1.2. Rust 环境配置

# Rustup install script
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

# Replace third-party crate source
touch .cargo/config
vim .cargo/config
[source.crates-io]
registry = "https://github.com/rust-lang/crates.io-index"

# 换成国内镜像
replace-with = 'ustc'

# 肥科
[source.ustc]
registry = "git://mirrors.ustc.edu.cn/crates.io-index"

# 上交
[source.sjtu]
registry = "https://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index"

# 清华
[source.tuna]
registry = "https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git"

[net]
git-fetch-with-cli = true
source .zshenv
mkdir Projects

cargo new hello
cd hello
cargo run

# 这时候会报错,因为 Rustup 不会查看编译器的工具链
------------------------------------------------------
error: linker `cc` not found
  |
  = note: No such file or directory (os error 2)

error: could not compile `hello` due to previous error
------------------------------------------------------

# 通过 ubuntu 上装置必要的工具链解决
apt install build-essential
cargo run
------------------------------------------------------
   Compiling hello v0.1.0 (/root/Projects/hello)
    Finished dev [unoptimized + debuginfo] target(s) in 0.33s
     Running `target/debug/hello`
Hello, world!
------------------------------------------------------
退出移动版