1

I have developed a java application that i want to publish to my users. This application is an ancillary application used by many different shell scripts, such as sh, su, bash and zsh to name a few. My current approach is to put my program in /opt/myapp with a sh script to run the app.

#!/bin/bash 
"$JAVA_HOME/bin/java" -jar /opt/myapp/myapp-1.0.jar $@

And I ask my users to add export PATH=$PATH:/opt/myapp to their source such as ~/.zsrch. However I keep having issues with some scripts or programs not finding the app bash: myapp: command not found however it would work fine in /bin/su and /bin/zhc.

What is the right way to "install" my app on Linux and MacOS so that it is available across all shells.

The /opt/myapp folder

bash-3.2$ ls -l
total 40624
-rwxr-xr-x  1 root  wheel        66 Apr  2 05:06 myapp
-rw-r--r--  1 root  wheel  20794374 Apr  2 05:05 myapp-1.0.jar

Path

bash-3.2$ echo $PATH
/opt/myapp:/Library/TeX/texbin::/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/usr/local/share/dotnet:~/.dotnet/tools:::/Users/accoun/bin

One of the examples is that an IntelliJ plugin runs the app to get information. The plugin will run /bin/bash -c myapp version as a process, however the output of that process is that bash: myapp: command not found. However if i open a console the run bash it worked just fine.

~ » /bin/bash                                    accoun@MACC02YX270LVDQ

The default interactive shell is now zsh.
To update your account to use zsh, please run `chsh -s /bin/zsh`.
For more details, please visit https://support.apple.com/kb/HT208050.
bash-3.2$ echo $PATH
/opt/myapp:/Library/TeX/texbin::/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/usr/local/share/dotnet:~/.dotnet/tools:::/Users/accoun/bin
bash-3.2$ myapp version
Myapp version 1.0
bash-3.2$
9
  • "I keep having issues" - what issues? Please edit and be explicit.
    – DavidPostill
    Apr 25, 2021 at 20:25
  • Are you a bot? It litterly says that "However I keep having issues with some scripts or programs not finding the app."
    – Androme
    Apr 25, 2021 at 20:27
  • So what are the error messages?
    – DavidPostill
    Apr 25, 2021 at 20:28
  • Not finding the app 'command not found', how is that not clear?
    – Androme
    Apr 25, 2021 at 20:29
  • 1
    This question has a very simple answer: Depending on where $PATH is changed/extended, the change may affect only Bash and/or only interactive shells. Put a symlink in /usr/local/bin and make sure that's in $PATH for all users.
    – Daniel B
    Apr 25, 2021 at 21:04

1 Answer 1

0

As @DanielB mentioned in the comments mentioned, both the problem and the solution are very simple. You have added your program/script/app to the wrong directory. You should add it to /usr/local/bin/ as that complies with the Filesystem Hierarchy Standard (and all defaults on the Linux system [on most distros] comply with the FHS). The said directory is by default in the $PATH variable of bash, so it will be accessible for all scripts and applications.

Scripts and applications do not use your .bashrc or your $PATH variable. Most of those will use the $PATH variable that is set in /etc/profile. Reason for this being is that scripts and applications run in a non-interactive shell. You can also refer to this SO answer.

So you have two options at first glance:

  1. Add the application to /usr/local/bin/ - better practice.
  2. Leave it in /opt/ and add that path to the $PATH variable in /etc/profile.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .