侧边栏壁纸
  • 累计撰写 122 篇文章
  • 累计创建 68 个标签
  • 累计收到 1 条评论

目 录CONTENT

文章目录

Linux系统初始化配置

刘少锋
2022-07-28 / 0 评论 / 0 点赞 / 221 阅读 / 873 字

更换镜像源

Ubuntu

将Ubuntu镜像源设置为清华镜像

sudo sed -i 's/archive.ubuntu.com/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list && sudo apt update

终端个性化配置

安装zsh

sudo apt install zsh git wget -y 

下载脚本到本地安装ohmyzsh

git clone https://mirrors.tuna.tsinghua.edu.cn/git/ohmyzsh.git && cd ohmyzsh/tools && REMOTE=https://mirrors.tuna.tsinghua.edu.cn/git/ohmyzsh.git sh install.sh
rm -rf ohmyzsh

或者直接使用在线脚本安装

sh -c "$(wget -O- https://raw.fastgit.org/ohmyzsh/ohmyzsh/master/tools/install.sh)"

安装ohmyzsh必备插件

git clone https://hub.fastgit.xyz/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
git clone https://hub.fastgit.xyz/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
sed -i 's/^plugins=.*$/plugins=(git sudo git-auto-fetch zsh-syntax-highlighting zsh-autosuggestions)/' ~/.zshrc && source ~/.zshrc

homebrew

在终端临时设置镜像镜像,方便第一次安装时加速

export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles"

下载脚本到本地安装

git clone --depth=1 https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/install.git brew-install
/bin/bash brew-install/install.sh
rm -rf brew-install

test -r ~/.zshrc && echo 'export PATH="/home/linuxbrew/.linuxbrew/bin:$PATH"' >> ~/.zshrc && source ~/.zshrc

或者直接使用在线脚本安装

/bin/bash -c "$(curl -fsSL https://hub.fastgit.xyz/Homebrew/install/raw/master/install.sh)"

将镜像写到配置文件.zprofile中,永久生效

test -r ~/.zprofile || touch ~/.zprofile
test -d /home/linuxbrew/.linuxbrew && eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
test -r ~/.zprofile && echo 'eval "\$($(brew --prefix)/bin/brew shellenv)"' >> ~/.zprofile

test -r ~/.zprofile && echo 'export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"' >> ~/.zprofile  # zsh
test -r ~/.zprofile && echo 'export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"' >> ~/.zprofile
test -r ~/.zprofile && echo 'export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles"' >> ~/.zprofile

python

源码编译安装

安装编译环境包

sudo apt-get update && sudo apt-get install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev wget libbz2-dev -y

下载源码到本地

sudo mkdir -p /usr/local/python && cd /usr/local/python && sudo wget https://registry.npmmirror.com/-/binary/python/3.9.13/Python-3.9.13.tgz && sudo tar zxvf Python-3.9.13.tgz -C ./ && sudo mv Python-3.9.13 3.9.13 && sudo rm -rf Python-3.9.13.tgz

编译源码

cd /usr/local/python/3.9.13 && sudo ./configure --enable-optimizations  && sudo make altinstall

创建链接

sudo rm -rf /usr/bin/python && sudo ln -s /usr/local/bin/python3.9 /usr/bin/python

PPA源安装

安装ppa源管理工具

sudo apt update && sudo apt install software-properties-common -y

添加ppa

sudo add-apt-repository ppa:deadsnakes/ppa

安装python3.9

sudo apt update && sudo apt install python3.9

brew命令安装

直接使用brew install安装

brew install python@3.9

在安装python的同时,还会安装对应的pip

sudo rm -rf /usr/bin/python /usr/bin/pip
sudo ln -s /home/linuxbrew/.linuxbrew/bin/python3.9 /usr/bin/python
sudo ln -s /home/linuxbrew/.linuxbrew/bin/pip3.9 /usr/bin/pip

pip

使用脚本安装特定python对应的pip

wget https://bootstrap.pypa.io/get-pip.py && sudo python3.9 get-pip.py -i https://pypi.tuna.tsinghua.edu.cn/simple/ 

创建链接

sudo rm -rf /usr/bin/pip && sudo rm -rf /usr/bin/pip3 && sudo ln -s /usr/local/bin/pip3 /usr/bin/pip && sudo ln -s /usr/local/bin/pip3 /usr/bin/pip3

设置镜像

pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
0

评论区