You should not run this command as root and neither able to install bench without root getting permission error

I have an complected issue.
First i was getting error on file upload. So i looked for solution and i found solution that i need to run

bench switch-to-master

i did this after that is asked me to run bench --update.
When i tried this it gave me error
You should not run this command as root
Because i was using sudo. So i tried too install without sudo. Then i got permission error.

Collecting python-crontab (from bench==4.1.0)

Exception:
Traceback (most recent call last):
File “/usr/lib/python2.7/dist-packages/pip/basecommand.py”, line 215, in main
status = self.run(options, args)
File “/usr/lib/python2.7/dist-packages/pip/commands/install.py”, line 342, in run
requirement_set.prepare_files(finder)
File “/usr/lib/python2.7/dist-packages/pip/req/req_set.py”, line 380, in prepare_files
ignore_dependencies=self.ignore_dependencies))
File “/usr/lib/python2.7/dist-packages/pip/req/req_set.py”, line 554, in _prepare_file
require_hashes
File “/usr/lib/python2.7/dist-packages/pip/req/req_install.py”, line 281, in populate_link
self.link = self._wheel_cache.cached_wheel(self.link, self.name)
File “/usr/lib/python2.7/dist-packages/pip/wheel.py”, line 68, in cached_wheel
self._cache_dir, link, self._format_control, package_name)
File “/usr/lib/python2.7/dist-packages/pip/wheel.py”, line 129, in cached_wheel
wheel_names = os.listdir(root)
OSError: [Errno 13] Permission denied: ‘/root/.cache/pip/wheels/45/c2/12/4f9e435a355df948f562120991107677bf2dce1bb86b18e751’

So i am stuck bench command is not working because it is installed as root user. And normal user unable to install bench.
Please provide solution for issue.

You should use/create a user called frappe, and give it sudo permissions, then run the install as that user, and use

sudo command_goes_here

for the things that need elevated permissions

I was doing like this and it was working before. But after switching to master it is not work anymore. Now if use sudo with any command it gives me error

You should not run this command as root

I was doing like this and it was working before. But after switching to master it is not work anymore. Now if use sudo with any command it gives me error

You should not run this command as root

Please provide any other possible solution

“Now if use sudo with any command it gives me error”

Yes correct, bench commands should not be run with sudo.

For example it seems ‘sudo bench update’ can change file ownership that causes permission issues (that you possibly can fix with chown.)

See this thread Bench Update: Issues with permissions

Before you run another install, you should remove the previous install How do I uninstall erpnext my server? - #13 by Ahmad_Moustafa

I think i have to reinstall it. But i don’t prefer it.
I have pass previous issue but got new one on bench update

INFO:bench.utils:updating bench
INFO:bench.utils:git pull
error: cannot open .git/FETCH_HEAD: Permission denied
Traceback (most recent call last):
File “/usr/local/bin/bench”, line 11, in
load_entry_point(‘bench’, ‘console_scripts’, ‘bench’)()
File “/home/erpuser/bench/bench/cli.py”, line 40, in cli
bench_command()
File “/usr/local/lib/python2.7/dist-packages/click/core.py”, line 764, in call
return self.main(*args, **kwargs)
File “/usr/local/lib/python2.7/dist-packages/click/core.py”, line 717, in main
rv = self.invoke(ctx)
File “/usr/local/lib/python2.7/dist-packages/click/core.py”, line 1137, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/usr/local/lib/python2.7/dist-packages/click/core.py”, line 956, in invoke
return ctx.invoke(self.callback, **ctx.params)
File “/usr/local/lib/python2.7/dist-packages/click/core.py”, line 555, in invoke
return callback(*args, **kwargs)
File “/home/erpuser/bench/bench/commands/update.py”, line 36, in update
update_bench()
File “/home/erpuser/bench/bench/utils.py”, line 260, in update_bench
exec_cmd(“git pull”, cwd=cwd)
File “/home/erpuser/bench/bench/utils.py”, line 159, in exec_cmd
raise CommandFailedError(cmd)
bench.utils.CommandFailedError: git pull

Not working with sudo. Not even with root user

This may help clarify [Solved] Bench Update Permission Error v10

Found the solution. bench was installed in the current user but. current user was not in the bash.
Example:-
Username:- erpuser
when i was logged in with erp user and run command.

echo $PATH

The output was.

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

It has missing this.

/home/erpuser/.local/bin

So i run:

export $PATH=/home/erpuser/.local/bin

Now i run echo $PATH again then output:

/home/erpuser/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

And then run “bench”. It starts working without any use of sudo. Because it is installed in /home/erpuser/.local/bin for user erpuser

I hope this will help someone else to solve same issue.

2 Likes

I had a similar experience in my case I determined a ‘bad’ install artifact /home/frappe/.local bench.utils.CommandFailedError: npm install - #40 by clarkej

It doesn’t really matter what should happen or not. Something in the underlying system has changed and is impacting users.