/usr/local/bin/zsh: line 2: exec: pkgx: not found
magnusviri opened this issue · comments
This is more of an FYI since I'm not even sure what you guys would do about it, if you should do anything at all. I often run the items installed by pkgx as daemon type stuff and the location of my pkgx isn't found. I installed pkgx at /usr/local/bin/pkgx to try to get around this, but I still see the "not found" error. To get around this, I've had to put in the full path of pkgx in the installed shims. E.g.
#!/bin/sh
exec /usr/local/bin/pkgx +zsh.sourceforge.io -- zsh "$@"
In this particular instance, I got the /usr/local/bin/zsh: line 2: exec: pkgx: not found
error by running a python script from BBEdit! When I have a script open in BBEdit, I can press command-R ("#!" menu -> "Run") and it will execute the script. The script starts with #!/usr/bin/env python
. When I run /usr/bin/env python
from the Terminal it works. So I'm not exactly sure what BBEdit is doing different. But I've also see this with other commands. I honestly don't remember all the times I've seen it. I use Ansible a lot to run commands, launchdaemons, and other automation techniques.
So if I understand you correctly a command like
#!/bin/sh
exec pkgx +node@latest
wouldn't work?
That's correct. It returns the error line 3: exec: pkgx: not found
. I have to modify all of the stubs that pkgx installs to the full path of pkgx.
Again, this is happening because as a system administrator I run commands with Ansible and Apple Remote Desktop and in those instances the PATH variable does not include /usr/local/bin/.
A possible fix would be something like this in the stub:
if command -v pkgx >/dev/null; then
PKGX=pkgx
elif test -x /usr/local/bin/pkgx; then
PKGX=/usr/local/bin/pkgx
else
echo "pkgx not found in any usual way; aborting..."
exit 1
fi
exec $PKGX ...
macOS doesn’t add /usr/local/bin
to the PATH
for things that operate below the shell layer (includes GUI apps).
You can fix this or you can configure the thing that daemonizes your scripts to add that PATH.
I don’t see this is our problem to fix though. Hardcoding the path to pkgx
is non-standard and not portable. So it seems like that would be a worse choice. Happy to continue talking. Reopen if you want.
I know this isn't your problem but I keep running into this. I get this error when running https://github.com/ivanfioravanti/autogram.
There are ways to modify the PATH globally, but it looks like Apple is disabling them all! The current way appears to be launchctl setenv PATH $PATH
but now that generates this error:
Could not set environment: 150: Operation not permitted while System Integrity Protection is engaged
. I'm a bit frustrated...
My bad, it looks like launchctl setenv PATH $PATH
works. I got the error because I tried to run it as root. I think you should add this to your documentation. I just looked at the wiki and there's some out-of-date info in there. I don't think any of that is valid anymore.
@michaelessiet can you update the wiki so it is up to date pls.