安装node npm yarn python等

本文详细介绍了多种安装Node.js的方法,包括使用nvm、nodesource以及手动下载低版本。同时涵盖了npm镜像配置、yarn的安装与常用命令,以及Python的编译安装步骤,适合开发者快速搭建环境。

作者:zhuge···预计阅读 11 分钟·5,694 阅读·0 评论
安装node npm yarn python等

有多种nodejs安装方法 nodejs官网 https://nodejs.org/zh-cn/download nvm:https://github.com/nvm-sh/nvm/releases

使用nvm安装 nvm install 23 nvm install 22 nvm install 20

# Download and install nvm:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash

#执行
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

# Download and install Node.js:
nvm install 23

# Verify the Node.js version:
node -v # Should print "v23.9.0".
nvm current # Should print "v23.9.0".

# Verify npm version:
npm -v # Should print "10.9.2".

使用 nodesource 安装 20.x

curl -fsSL https://deb.nodesource.com/setup_20.x | sudo bash -
sudo apt-get install -y nodejs

22.x

curl -fsSL https://deb.nodesource.com/setup_22.x | sudo bash -
sudo apt-get install -y nodejs

低版本安装以安装 nodejs 16 为例

wget https://nodejs.org/dist/v16.16.0/node-v16.16.0-linux-x64.tar.xz
tar -xf node-v16.16.0-linux-x64.tar.xz 
vim /etc/profile
export NODE_HOME=/opt/node-v16.16.0-linux-x64
export PATH=$NODE_HOME/bin:$PATH
source /etc/profile
or 使用以下的方法时,如果安装了yarn还需要重新再建立软连接
ln -s /opt/node-v16.16.0-linux-x64/bin/npm /usr/local/bin/
ln -s /opt/node-v16.16.0-linux-x64/bin/node /usr/local/bin/
--npm编译到指定路径
npm run build -- --dest='../dist'
-- 查看当前地址:
npm config get registry
https://registry.npmjs.org/
npm config get disturl
undefined
-- 设置当前地址(设置为淘宝镜像)
npm config set registry http://registry.npm.taobao.org/
-- 设置当前地址(设置为默认地址)
npm config set registry https://registry.npmjs.org/
-- 每次执行命令前加入–registry指定仓库路径
npm --registry https://registry.npm.taobao.org install
#安装yarn
npm install yarn -g
yarn config set registry https://registry.npm.taobao.org -g
yarn config set sass_binary_site http://cdn.npm.taobao.org/dist/node-sass -g
yarn config get registry // https://registry.npm.taobao.org
一些常用的Yarn命令
yarn init // 生成package.json文件
yarn install // 安装yarn.lock的所有依赖
yarn install --force // 重新安装依赖
yarn remove moduleName // 删除依赖
yarn add moduleName // 安装某个依赖
yarn add moduleName --dev/-D // 安装到开发环境
yarn run scriptName // 执行package.json命名的脚本命令
#安装python
https://www.python.org/ftp/python/
wget https://www.python.org/ftp/python/3.10.6/Python-3.10.6.tar.xz
mkdir /usr/local/python3
cd /usr/local/src
wget https://www.python.org/ftp/python/3.10.6/Python-3.10.6.tar.xz
yum -y install libffi-devel zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
tar -xvJf  Python-3.10.6.tar.xz
cd Python-3.10.6
./configure --prefix=/usr/local/python3
make && make install
安装Python3时,会自动安装pip。假如没有,需要自己手动安装。
#yum -y install python-pip
创建软链接$ 
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
pip3 install --upgrade pip
vim /etc/profile.d/python.sh
alias python="/usr/bin/python3"
chmod 755 /etc/profile.d/python.sh
source /etc/profile.d/python.sh

相关文章

评论

加载中...