返回首页
27/02/2024

Ubuntu20安装node20,mongodb6.0和redis、yarn

安装 Node.js 20 和 MongoDB 6.0 以及 Redis 在 Ubuntu 20.04 上的步骤如下:

安装 Node.js 20和yarn:

使用 nvm 安装 Node.js,首先确保您的系统已安装 curl 工具:

   sudo apt update
   sudo apt install curl

安装 nvm(Node Version Manager):

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

重新加载终端,使 nvm 命令生效:

   source ~/.bashrc

安装 Node.js 20:

   nvm install 20

使用以下命令验证安装是否成功:

   node -v

安装yarn

corepack enable



安装 MongoDB 6.0:

添加 MongoDB 的官方仓库:

  sudo apt-get install gnupg curl
  curl -fsSL https://www.mongodb.org/static/pgp/server-6.0.asc | \

添加 MongoDB 6.0 版本的软件源:

   echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list

更新包列表:

   sudo apt update

安装 MongoDB:

   sudo apt install -y mongodb-org

启动 MongoDB 服务:

   sudo systemctl start mongod

设置 MongoDB 开机自启动:

   sudo systemctl enable mongod

使用以下命令验证 MongoDB 是否正常运行:

   sudo systemctl status mongod

补充,如果是完全覆盖数据文件夹,则还需运行:

chown -R mongodb:mongodb /var/lib/mongodb
systemctl restart mongod

安装 Redis:

使用以下命令安装 Redis:

   sudo apt update
   sudo apt install redis-server

启动 Redis 服务:

   sudo systemctl start redis-server

设置 Redis 开机自启动:

   sudo systemctl enable redis-server

使用以下命令验证 Redis 是否正常运行:

   sudo systemctl status redis-server

现在,您已经成功在 Ubuntu 20.04 上安装了 Node.js 20、MongoDB 6.0 和 Redis。