[RAILS] [Error] Regarding rbenv: ruby 2.5.1 is not installed ot ~ when executing automatic deployment

Introduction

This post was addicted to an error when I performed an automatic deploy, so I'll share it.

error contents

[Deprecation Notice] Future versions of Capistrano will not load the Git SCM
plugin by default. To silence this deprecation warning, add the following to
your Capfile after `require "capistrano/deploy"`:

    require "capistrano/scm/git"
    install_plugin Capistrano::SCM::Git

00:00 rbenv:validate
      WARN  rbenv: ruby 2.5.1 is not installed or not found in $HOME/.rbenv/versions/ruby 2.5.1 on 54.95.87.53

Make a hypothesis

1. require "capistrano/scm/git" It is hypothesized that there is an abnormality in Capfile from the description of require ~.

2. WARN rbenv: ruby 2.5.1 is not installed〜 From the description that ruby 2.5.1 is not installed, it is hypothesized that ruby 2.5.1 is not installed and that there is a difference in ver from the local environment. Is it suspicious deploy.rb ...?

Temporary verification Capfile

require "capistrano/setup"
require "capistrano/deploy"
require 'capistrano/rbenv'
require 'capistrano/bundler'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'
require 'capistrano3/unicorn'
require "capistrano/scm/git"
install_plugin Capistrano::SCM::Git

Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }

No particular abnormality.

Temporary verification ver confirmation

I ran ** ruby -v ** in my local development environment and production environment (EC2), but there is no problem.

Temporary verification deploy.rb

deploy.rb


# config valid only for current version of Capistrano
#Described the version of capistrano. Continue to use the fixed version and prevent troubles due to version change
lock '3.14.1'

#Used to display Capistrano logs
set :application, 'chat-space'

#Specify from which repository the app should be pulled
set :repo_url,  '[email protected]:ken-sasaki-222/chat-space.git'

#Specify a directory to be referenced in common even if the version changes
set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system', 'public/uploads')

set :rbenv_type, :user
set :rbenv_ruby, 'ruby2.5.1' #Pay attention here

#Which public key to use for deployment
set :ssh_options, auth_methods: ['publickey'],
                  keys: ['~/.ssh/test_key.pem'] 

#Location of the file containing the process number
set :unicorn_pid, -> { "#{shared_path}/tmp/pids/unicorn.pid" }

#Location of Unicorn configuration files
set :unicorn_config_path, -> { "#{current_path}/config/unicorn.rb" }
set :keep_releases, 5

#Description for restarting Unicorn after the deployment process is finished
after 'deploy:publishing', 'deploy:restart'
namespace :deploy do
  task :restart do
    invoke 'unicorn:restart'
  end
end

There seems to be no problem with ruby ver. I think ... The part specified by ver is 'ruby 2.5.1'!

Correctly, '2.5.1' is OK! If you fix it.

deploy.rb


#abridgement

set :rbenv_type, :user
set :rbenv_ruby, '2.5.1' #Pay attention here

#abridgement

Now when you run ** bndle exec cap production deploy ** in your local terminal The automatic deployment ran safely.

Recommended Posts

[Error] Regarding rbenv: ruby 2.5.1 is not installed ot ~ when executing automatic deployment
Workaround for Bundler.require error when executing ruby with crontab
[Ruby] How to use rbenv (version `x.x.x'is not installed)
Correspondence when Ruby version does not switch in rbenv
Yarn is not installed
When an error occurs even though validation is not set
An error occurs when codedeploy-agent is installed in Ubuntu Server 20.04
"tx" is not bound error