0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

pm2 --update-env で環境変数が更新できなかった時の対応メモ

Last updated at Posted at 2025-10-21

これは何?

pm2で管理しているNode.jsアプリ環境において、.envファイルに新しく追記した環境変数が反映されない問題が起きた。
pm2を再起動することで反映されたため、その時の手順をメモ。

環境

Ubuntu: 24.04.1 LTS
pm2: 5.4.2

ダメだったコマンド

アプリの .envに環境変数が追加されていることを確認し、以下を実行したが、効果がなかった。

pm2 restart <app_name> --update-env

有効だったコマンド

pm2 delete で一度プロセスを削除してから、再起動することで反映された。
再起動後は, pm2 save で変更を保存しておく。

pm2 delete <app_name>
pm2 start ecosystem.config.cjs
pm2 save

<app_name> に入れるアプリ名は、pm2 list コマンドで確認できる。

pm2 list
#以下の name の箇所に表示される
┌────┬──────────────────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
 id  name                      namespace    version  mode     pid       uptime       status     cpu       mem       user      watching 
├────┼──────────────────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
 1   app-name                  default      N/A      fork     1488201   2h      15    online     0%        103.4mb   ubuntu    disabled 
└────┴──────────────────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
Module
┌────┬──────────────────────────────┬───────────────┬──────────┬──────────┬──────┬──────────┬──────────┬──────────┐
 id  module                        version        pid       status         cpu       mem       user     
├────┼──────────────────────────────┼───────────────┼──────────┼──────────┼──────┼──────────┼──────────┼──────────┤
 0   pm2-logrotate                 2.7.0          1488171   online    1     0%        64.5mb    ubuntu   
└────┴──────────────────────────────┴───────────────┴──────────┴──────────┴──────┴──────────┴──────────┴──────────┘
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?