linux npm 修改 源_修改apt,pip,npm为国内镜像源

apt

原文件备份

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

编辑源列表文件

sudo vim /etc/apt/sources.list

将原来的列表删除,添加如下内容(中科大镜像源)

deb http://mirrors.ustc.edu.cn/ubuntu/ xenial main restricted universe multiverse

deb http://mirrors.ustc.edu.cn/ubuntu/ xenial-security main restricted universe multiverse

deb http://mirrors.ustc.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse

deb http://mirrors.ustc.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse

deb http://mirrors.ustc.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse

deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial main restricted universe multiverse

deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-security main restricted universe multiverse

deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse

deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse

deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse

npm

直接使用

sudo npm install --registry https://registry.npm.taobao.org/

命令行永久修改

# 1. 设置

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

# 2. 查看

npm config get registry

# 如果不需要可以直接删除

npm config rm registry

使用cnpm

sudo npm install -g cnpm --registry=https://registry.npm.taobao.org

# 使用npm时,直接使用cnpm

cnpm install

pip

临时使用

sudo pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple

# 或者

python3 -m pip install -i https://pypi.tuna.tsinghua.edu.cn/simple

命令行永久修改(pip 版本 >= 10.0.0)

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

# 查看

$ pip config get global.index-url

配置文件修改

mkdir ~/.pip

vim ~/.pip/pip.conf

编辑以下内容

[global]

index-url = https://pypi.tuna.tsinghua.edu.cn/simple

[install]

trusted-host = pypi.tuna.tsinghua.edu.cn

window下在"C:\Users\Administrator\AppData\Roaming\创建pip\pip.ini"

[global]

index-url = http://pypi.douban.com/simple

[install]

trusted-host = pypi.douban.com

docker

临时使用

sudo docker pull docker.mirrors.ustc.edu.cn//

持久使用

sudo vim /etc/docker/daemon.json

{

"registry-mirrors": ["https://docker.mirrors.ustc.edu.cn/"]

}

sudo systemctl restart docker

你可能感兴趣的:(linux,npm,修改,源)