4

I am new to the Mac philosophy, but I have been using Ubuntu since a while. Now I am using Mac at work, and I have to install a few programs, not apps, from source code distribution.

I did try to gunzip a folder in /usr/local/ but it says permission denied. Same result with sudo. The su command just freezes.

Is /Users/ a better place to go? I suppose I do not need permission to write in there, right?

Where should I install new software (from source code distribution) on a Mac?

Nimesh Neema
  • 51,809
Py-ser
  • 183

2 Answers2

5

To start we should define a few terms. An install from source code means that the software needs to be built before it can be executed.

So your first step is to find a place on your computer to perform the build. The best place for this is a directory in your home directory. I use a directory at ~/src/ to hold the packages. So, create this folder and unpack your source into here. Then you can build the software here.

When it comes to the executable files man hier will tell you that /usr/local is the place to install things not included in the OS. Homebrew, for example, will install into here. So executables should go into /usr/local/bin. Most software packages will have an install tool that will perform this step. Of course /usr/local/bin needs to be in your PATH variable.

This is identical to Ubuntu in almost every respect.

Tony Williams
  • 12,142
  • Thanks. Why I am not supposed to build the program in the same directory as where I want to store the executable? For memory purposes? – Py-ser Apr 09 '18 at 15:26
  • 2
    You build in a different spot for reasons of neatness and purpose. – Tony Williams Apr 09 '18 at 20:30
  • @Pyser Also, for security reasons: on most systems, you’re going to store the executable in a place that needs root privileges to write. If you were to build the executable in that same place, you’d have to grant root privileges to the entire build process. That could be highly dangerous because the build process can usually execute arbitrary code, while installing is just copying files. – Synoli Jan 12 '19 at 11:33
1

I did try to gunzip a folder in /usr/local/ but it says permission denied.

/usr/local/ is a protected directory in macOS. The observed behaviour in your case is due to System Integrity Protection. SIP does not allow even the root user or using sudo to chown /usr/local/.

As per man hier, /usr/local/ is the recommended directory for placing executables, libraries, etc. not included by the basic operating system. So it is where you should be installing your software (from source). The approach to take here is to create a directory under /usr/local and chown it to logged in user. This new directory can be used to install new software as per your liking.

/Users/ houses the users home directories, along with a Shared directory, shared between users. So, this is not the place to install new software, whether from source or not.

You can also refer to this nicely written answer discussing Standard for macOS filesystem.

Nimesh Neema
  • 51,809
  • 2
    I think the right terminology to explain why I can not use brew, is that we are talking of source code software. – Py-ser Apr 06 '18 at 20:31
  • /usr/local indeed, what about my original post? – Py-ser Apr 06 '18 at 20:35
  • Can I chown directly on /usr/local? This way I do not need to repeat the process for every other installed software... – Py-ser Apr 06 '18 at 20:40
  • If you would just explain the main differences between a local installation and a global (is this the right term?) one, and say a few word on why the local is preferable, I would be happy to accept your answer. – Py-ser Apr 06 '18 at 20:46
  • so, why I can't actually install there, if that is supposed to be the standard? why I need to create additional folders, and change settings, etc if that is supposed to be the default? – Py-ser Apr 06 '18 at 20:55
  • Updated and corrected the answer to include relevant information and encompass discussion from comments. – Nimesh Neema Apr 07 '18 at 12:03
  • 1
    No! Your first paragraph is incorrect! /usr/local/ is not protected by SIP. From the link to SIP you posted: *Paths and apps that third-party apps and installers can continue to write to include.... /usr/local. – Allan Apr 09 '18 at 13:19
  • 1
    I would remove it. The issue with sudo having the same results needs to be looked into - does he have rw permissions to /usr/local? – Allan Apr 09 '18 at 13:37
  • Okay. I am not sure. It appears he doesn't have the permission as it is mentioned in the question: I did try to gunzip a folder in usr/local/ but it says permission denied. Same result with sudo. – Nimesh Neema Apr 09 '18 at 13:47