部署第一个Rails项目

安装Ruby2.3.8

  • 由于ubuntu22.04使用的是openssl3,于是之前安装ruby时安装的是ruby3.2.2版本。但是rotten-potatoes项目使用的ruby需要2.3.8版本,于是需要先安装ruby2.3.8

安装openssl1

  • 要安装ruby2.3.8版本就需要先安装openssl1,在终端输入以下命令
rvm pkg install openssl

安装ruby2.3.8

  • 使用命令行安装ruby2.3.8(安装时可能需要输入登录密码)
rvm install ruby-2.3.8

设置默认使用ruby2.3.8

  • 使用命令行配置默认使用2.3.8版本的ruby(如果是第一次安装ruby,则需要打开终端偏好设置,找到unnamed > Command > 勾选 Run command as login shell,并重新登录系统)
rvm install ruby-2.3.8 --default

克隆项目

  • 使用命令行克隆rotten-potatoes项目
git clone https://gitee.com/shinabc/rotten-potatoes.git

安装依赖

  • 在终端安装项目所需的nodejs以及数据库依赖
sudo apt install libpq-dev  (安装数据库依赖)
sudo apt install nodejs      (安装nodejs)

编译项目

  • 进入项目文件夹
  • 运行以下代码安装项目的所有依赖
bundle install --without production

项目初始化

  • 在项目文件夹下运行以下代码来初始化项目
rake db:setup
rake db:migrate           (初始化数据库)
rake db:seed  

运行项目

  • 在项目文件夹下运行以下代码来启动项目
rails server                   (启动服务器)

  • 打开浏览器,访问http://localhost:3000/ ,发现项目成功运行!

猜你喜欢

转载自blog.csdn.net/Qudoudou2020/article/details/133975757
今日推荐