·

Nginx is installed but command not found

Published at 2024-06-06 20:16:35Viewed 392 times
Professional article
Please reprint with source link

Problem. I installed nginx on my Debian 12 server following the steps in the official documentation Installing NGINX Open Source | NGINX Documentation. At first, everything is OK😇. Running sudo nginx -v returns the correct version of nginx.

However, recently, when I ran the same command, it returned command not found:

sudo nginx
sudo: nginx: command not found

nginx
bash: nginx: command not found

Either sudo nginx or nginx gives the same result😣.

Solution. To solve this problem, first you need to determine the path of your installed nginx. Your nginx may be contained in /usr/local/sbin or /usr/sbin. Once you find your nginx path, for instance, /usr/local/sbin/nginx, you can directly run

sudo /usr/local/sbin/nginx -v
nginx version: nginx/1.22.1

This would output the version of nginx, which solves the problem.

However, if you don't want to input the entire path of nginx everytime, you must add the path of nginx to the environment variables as follows.

First, output the environment variables by running echo $PATH. You may found that the path of nginx is not in the output. Meanwhile, the output of the command which nginx is also void. Therefore, you need to check the file of environment variables:

sudo vim /etc/profile

In /etc/profile, I found that /usr/local/sbin and /usr/sbin are in PATH only when I'm a root user. So we just need to add /usr/local/sbin or /usr/sbin to another PATH. For example:

if [ $(id -u) -eq 0 ]; then
   PATH="/usr/local/sbin:/usr/local/sbin:..."
else
   PATH="/usr/local/sbin:/usr/local/sbin:..."
fi
export PATH

After saving /etc/profile, reset the command line

source /etc/profile

Then run nginx -v to check if it returns the correct version😄.

nginx -v
nginx version: nginx/1.22.1


0 人喜欢

Comments

There is no comment, let's add the first one.

弦圈热门内容

Get connected with us on social networks! Twitter

©2024 Guangzhou Sinephony Technology Co., Ltd All Rights Reserved