'Why do I get "foreman: command not found" only in a directory *with* a Procfile?

I am on CentOS. I've installed foreman with yum

In my home directory, with no Procfile I get:

$ foreman start
ERROR: Procfile does not exist.

However when I cd into a directory that has a Procfile, for example:

cd ~/supersender

Then the foreman command is unavailable, i.e. forem [tab][[tab] does not complete and I get

$ foreman start
-bash: foreman: command not found


Solution 1:[1]

I had this problem after installing foreman globally via gem install foreman.

I had installed it whilst using Ruby 2.7.1 (via rvm), but my project uses Ruby 3.1.0, so it couldn't find it.

Switching to 3.1.0, then installing again fixed it for me.

rvm use 3.1.0 && gem install foreman

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 developius