Sudo: bench: command not found

When I run sudo bench setup production, I get the error “sudo: bench: command not found”. Without sudo, the bench command works correctly.

erpnext@ubuntu-s-1vcpu-2gb-amd-blr1-01:~/erpnext$ bench setup production
WARN: superuser privileges required for this command
erpnext@ubuntu-s-1vcpu-2gb-amd-blr1-01:~/erpnext$ sudo bench setup production
sudo: bench: command not found
erpnext@ubuntu-s-1vcpu-2gb-amd-blr1-01:~/erpnext$ which bench
/home/erpnext/.local/bin/bench
erpnext@ubuntu-s-1vcpu-2gb-amd-blr1-01:~/erpnext$ sudo /home/erpnext/.local/bin/bench setup production
Traceback (most recent call last):
  File "/home/erpnext/.local/bin/bench", line 5, in <module>
    from bench.cli import cli
ModuleNotFoundError: No module named 'bench'
erpnext@ubuntu-s-1vcpu-2gb-amd-blr1-01:~/erpnext$

How do I get bench command work with sudo?

Hi @ServerOK ,

The bench commend only works on your frappe-bench installed directory. By default, the folder name will be frappe-bench. So, try to find that folder, get into it, and run all your bench commends.

Hope this will help you out.
Thank you.

I used the following command to create the frappe-bench

bench init --frappe-branch version-13 erpnext

Since erpnext is specified at the end of the command, it created folder “erpnext”, I am inside this folder, and bench command works properly, the only problem is when running with the sudo command.

See “bench --site all list-apps” works properly.

erpnext@ubuntu-s-1vcpu-2gb-amd-blr1-01:~/erpnext$ bench --site all list-apps
frappe
erpnext
erpnext@ubuntu-s-1vcpu-2gb-amd-blr1-01:~/erpnext$

Hi,

See if: sudo pip3 install frappe-bench helps.

Hi, I think This is Useful

  1. bench init frappe-bench --verbose --frappe-branch version-13
  2. cd frappe-bench
  3. bench get-app --branch version-13 erpnext

if you want to create a site Lets continue:

  1. bench new-site site.itanand.com
  2. bench --site site.itanand.com
    install-app erpnext​

I am also experiencing this issue now. Anybody got any ideas??