2

tl;dr

Goal: Easily download zip file with a console app (and other files), execute it, and later replace it with updated version.

Details

When I want to download a console app, with a command-line interface, into what appropriate folder should I place it? I want the tool to be automatically present on the PATH.

I am not referring to the Apple developer tools from Xcode. I am asking about third-party tools such as Microsoft Kiota.

From what little I know about other Unix-oriented operating systems such as FreeBSD, /opt is the usual place for added third-party apps not controlled by the OS. I added a /opt to my macOS Sonoma 14.4.1 machine. I can explicitly run the console app from there. But that location does not seem to be on the PATH automatically.

I tried /usr/local and /usr/local/bin. But no go. Executing kiota --version results in "kiota not found".

screenshot in Finder.app of /usr/local

I found /usr/local/bin existing on my Mac. Several exiting items are found there, all related to Docker (presumably from my install of Docker Desktop app). All of those items are reported by the Finder.app as being "Alias", though I suspect they are actually symlinks. Using "Show original" in the Finder for those Docker items takes me to a folder nested within the GUI Mac app Docker.app. Placing my Kiota folder hierarchy within usr/local/bin does not result in putting kiota on the default PATH in Terminal.app, even after a system restart.

Workarounds

One workaround is to give up on the convenience of PATH. Drag and drop the kiota from any folder into the Terminal.app window. The tool then executes successfully:

/usr/local/Kiota/osx-arm64/kiota --version

1.14.0+fc4b39c65d89f7bfc8c7f1813c197e95e206da09

(1.14.0 is indeed expected, and correct.)

Another workaround is to manually add to the values within the PATH environment variable. But… the entire point of my Question is to avoid manipulating the PATH explicitly. As far as I know, all other Unix-oriented OSes such as BSD & Linux offer a default place for third-party console apps. I would expect the same in macOS.

Non-workarounds

Putting an alias (File > Make Alias in the Finder) of the kiota executable into /usr/local/bin does not work, even after system restart. which kiota results in "kiota not found".

17
  • @JohnPalmieri The entire point of my Question is to avoid manipulating the PATH explicitly. All other Unix-oriented OSes offer a default place for third-party console apps. I would expect the same in macOS. Commented May 4 at 21:48
  • 1
    When I built using brew install kiota on Intel Monterey, /usr/local/bin/kiota was created as a symbolic link to ../Cellar/kiota/1.11.1/bin/kiota, which is a bash script. This script contains the line #!/bin/bash followed by the line DOTNET_ROOT="${DOTNET_ROOT:-/usr/local/opt/dotnet/libexec}" exec "/usr/local/Cellar/kiota/1.11.1/libexec/kiota" "$@". Commented May 5 at 14:34
  • 1
    @DavidAnderson I edited the old answer to include the missing options.
    – nohillside
    Commented May 5 at 18:48
  • 1
    @David Anderson I don't think this is a duplicate - as I think the issue is that the OP is copying a directory into /usr/local/bin not the actual executable.
    – mmmmmm
    Commented May 5 at 19:55
  • 1
    "All other Unix-oriented OSes offer a default place for third-party console apps. I would expect the same in macOS." Other *nix OSes have package managers. macOS does not. Homebrew is a popular package manager for macOS. Despite your reluctance to add Homebrew for one app, it would solve your problem.
    – SteveM
    Commented May 5 at 21:08

5 Answers 5

6

macOS doesn‘t automagically organize /usr/local for you.

You can do one of the following, depending on the actual need:

  • Put the binaries or scripts directly into /usr/local/bin,
  • Put the package into its own directory (under /opt, /usr/local/opt or wherever you prefer), and run cd /usr/local/bin; sudo ln -s /path/to/package/bin/* . (Finder aliases are not symlinks and can't be used here). This only works if the binaries introduced by the package have unique names,
  • Add the whole package to /opt and the additional bin directories to /etc/paths.d/name-of-package.

Unless the package name/directory includes a version number, symlinking (option 2) or editing /etc/paths.d/name-of-package (option 3) need to be done only once.

PS: The second option is basically what Homebrew does.

7
  • Thanks. That was my own conclusion. It is just such a seemingly silly chore for me to have to create a new symlink in the /usr/local/bin folder every time I get an updated version of the console app. Commented May 5 at 0:07
  • 2
    @BasilBourque You only have to update the symlink if the target path changes. I honestly still don‘t fully understand the problem you are trying to solve here.
    – nohillside
    Commented May 5 at 5:38
  • My problem is simply this: I want to easily download a folder with a console app, execute it, and later replace it with new updated versions. I do not want to have to write scripts, create aliases, replace symlinks, or update arcane files in locations I can no longer remember just to run a newly updated console app. Commented May 5 at 20:17
  • 1
    "My problem is simply this: I want to easily download a folder with a console app, execute it, and later replace it with new updated versions." Then use a package manager like Homebrew. That is the solution to this exact problem.
    – SteveM
    Commented May 5 at 21:11
2

Kiota is available as a Homebrew package. This is documented on the Microsoft product page you linked. All of the decisions you are trying to get to grips with are handled for you, all taking into account the differences required by whatever Mac architecture you are using.

Path manipulation is inevitable, but brew will provide a standardised location that it can manage for you, once installed properly. Note that brew will require a one-off change to ~/.zprofile to set the paths.

With brew installed:

brew install kiota

0
1

Kiota contains four files including the command line program Kiota

To install just copy all of the programs into /usr/local/bin - with no Kiota directory.

What is needed here is to get the Kiota command line executable info /usr/local/bin

1

Another possibility is to put the binary wherever and define an alias to it in your shell. The latter part would need to be done for every user/shell combination. However, unless the binary is placed in a directory already covered by PATH, one has to iterate over all users, anyway.

Caveat: if the binary in question calls other binaries, they typically would need to be in PATH. Aliases will not work in that case, because they are shell only.

0

The usual place is inside /usr/local/

But you can of course add extra locations to $PATH.

The Kiota download comes with four files: one executable and 3 support files. You should put all of them in a folder anywhere, and then create a symlink to the executable inside /usr/local/bin/, so that the executable can be called from standard $PATH.

5
  • Nope. I put the folder containing my app in /usr/local. The app does not automatically became available via the PATH, even after a system restart. Commented May 4 at 21:05
  • 1
    @BasilBourque: /usr/local is the root. Executables would go in /usr/local/bin. Manual pages would go in /usr/local/share/man/. The PATH should already have /usr/local/bin included. You may need to create some of these directories. Commented May 4 at 21:27
  • /usr/local/bin exists on my Mac. Several exiting items are found there, all related to Docker (presumably from my install of Docker Desktop app). All of those items are reported by the Finder.app as being "Alias", though I suspect they are actually symlinks. Placing my Kiota folder hierarchy does not result in putting kiota on the default PATH in Terminal.app, even after a system restart. Commented May 4 at 21:41
  • @BasilBourque See my revised answer.
    – benwiggy
    Commented May 5 at 11:37
  • 2
    By alias, you mean symlink I assume? Might be worth being specific.
    – nohillside
    Commented May 5 at 13:15

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