# Node red on Mac mini m2 starting as a service can't execute commands via exec node

**URL:** <https://discourse.nodered.org/t/node-red-on-mac-mini-m2-starting-as-a-service-cant-execute-commands-via-exec-node/96684>\
**Category:** General\
**Created:** [21 April 2025 15:05 UTC](https://discourse.nodered.org/t/node-red-on-mac-mini-m2-starting-as-a-service-cant-execute-commands-via-exec-node/96684 "2025-04-21T15:05:20Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mac89muc](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mac89muc/32/100322_2.png) [@mac89muc](https://discourse.nodered.org/u/mac89muc)\
**Post date:** [21 April 2025 15:05 UTC](https://discourse.nodered.org/t/node-red-on-mac-mini-m2-starting-as-a-service-cant-execute-commands-via-exec-node/96684/1 "2025-04-21T15:05:20Z")

</div>

Hello I've installed node-red on my macmini m2 running 15.4.1 Sequoia.

Everything is working fine - if is start NR by terminal (cmd node-red) the exec node is working as expected - commands are executed correctly.

But if NR is starting automatically on startup via LaunchAgent script - I'm facing a problem concerning permissions I guess, when I try to execute commands via the exec node.  
The commands are not executed I recieve an error 127 e.g. `/bin/sh: cp: command not found`

Can someone point me to the right direction what I've to do ??

Thanks in advance

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [21 April 2025 16:53 UTC](https://discourse.nodered.org/t/node-red-on-mac-mini-m2-starting-as-a-service-cant-execute-commands-via-exec-node/96684/2 "2025-04-21T16:53:55Z")

</div>

Hi @mac89muc

Welcome to the forums 😃

One potential, the `cp` command is a binary in it's own right, it's not built into the shell

 ![Screenshot 2025-04-21 at 17.50.12](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/6/263f569ba445718075ae8f7c51effe0759dbe75b.png)

It's very possible, the `$PATH` variable is not seen by the process (node)

The `$PATH` variable contains the location of `/bin`

 ![Screenshot 2025-04-21 at 17.51.46](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/a/cae43c156e7d8c6d4b2864e22d8ca0204b6e0d66.png)

Maybe try printing the $PATH variable using the `exec` node to check if this variable is seen

```auto
$PATH

```

A **users** shell, will envelop the `$PATH` variable, and will check these location(s) for commands.

I'm using an M2 Pro Mini.  
But only Node RED on it for dev purposes

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [21 April 2025 20:33 UTC](https://discourse.nodered.org/t/node-red-on-mac-mini-m2-starting-as-a-service-cant-execute-commands-via-exec-node/96684/3 "2025-04-21T20:33:09Z")

</div>

Try using the command  
`which cp`  
to give you the full path to the command, and put that in the exec node. On my Ubuntu system I see

```auto
which cp
/usr/bin/cp

```

If that doesn't help, how did you install node-red? Is it running in Docker for example? If so then it may be necessary to install `cp` in the container.

---

<div class="post-metadata">

**Author:** ![mac89muc](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mac89muc/32/100322_2.png) [@mac89muc](https://discourse.nodered.org/u/mac89muc)\
**Post date:** [23 April 2025 12:36 UTC](https://discourse.nodered.org/t/node-red-on-mac-mini-m2-starting-as-a-service-cant-execute-commands-via-exec-node/96684/4 "2025-04-23T12:36:49Z")

</div>

thank you guys - that solution with the full path in the exec command is working for me.

`which cp` is giving me `/bin/cp`  
$PATH is containing /bin so is there a chance to give the node process access to the $PATH variable?

If I start nr by terminal command `node-red` I have no problems - only if I start the node-red process automatically by launch agent.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [23 April 2025 12:51 UTC](https://discourse.nodered.org/t/node-red-on-mac-mini-m2-starting-as-a-service-cant-execute-commands-via-exec-node/96684/5 "2025-04-23T12:51:11Z")

</div>

> [@mac89muc](#):
>
> is there a chance to give the node process access to the $PATH variable?

The problem is that when running automatically the PATH environment variable does not exist. I don't use Macs, but I expect that googling for something like  
`How to set an environment variable when starting with LaunchAgent`  
will help.

Though personally I would just use the full path rather than messing about with env vars.

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [23 April 2025 14:46 UTC](https://discourse.nodered.org/t/node-red-on-mac-mini-m2-starting-as-a-service-cant-execute-commands-via-exec-node/96684/6 "2025-04-23T14:46:44Z")

</div>

> [@mac89muc](#):
>
> is there a chance to give the node process access to the $PATH variable?

Add this to your launch agent plist

```auto
<key>EnvironmentVariables</key>
<dict>
    <key>PATH</key>
    <string>/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/sbin</string>
</dict>

```

@Colin's will work also, its just my preference to allow any launch agent's to see the path variable.

whatever works better for you.

its been a whilst since I done this, so research if committing to the above

source : [launchd - How to extend PATH of LaunchAgents in ~/Library/LaunchAgents? - Ask Different](https://apple.stackexchange.com/questions/405868/how-to-extend-path-of-launchagents-in-library-launchagents)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [17 May 2025 21:44 UTC](https://discourse.nodered.org/t/node-red-on-mac-mini-m2-starting-as-a-service-cant-execute-commands-via-exec-node/96684/7 "2025-05-17T21:44:27Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
