On Linux (Ubuntu 20.04), using yarn 3.2.0, had an issue where yarn install would always fail with a number of "permission denied" during the Link step, where it was trying to use other modules installed in node_modules as part of the same install (e.g. node-gyp, node-gyp-build, node-pre-gyp, prebuild-install).
Turns out after a long period of investigation (mainly focused on file permissions because of the permission denied error) that it was in fact down to Yarn's use of the /tmp folder, which it apparently uses during its Link step for placing and executing some files. This is all very well, but not on a Linux server which is following "best practice" in having the noexec flag on the /tmp mount point (see: /opt/fstab) ! noexec prevents use of executables, hence the permission denied. If I take the noexec flag off yarn works flawlessly.
So the question is, how do I get around this behaviour in Yarn so that I don't have to break best practice on the /tmp folder? I have dug hard into yarn's configuration options but there appears to be nothing in this area.
Fortunately, Yarn is respecting standard TMPDIR
variable. I'm guessing it is using standard NodeJS os.tmpdir()
method which supports this.
Citing Wikipedia's page about TMPDIR:
TMPDIR is the canonical environment variable in Unix and POSIX that should be used to specify a temporary directory for scratch space. Most Unix programs will honor this setting and use its value to denote the scratch area for temporary files instead of the common default of
/tmp
or/var/tmp
.
You can easily do something like:
mkdir ~/tmp && export TMPDIR=~/tmp && yarn install
Btw. I went through same deal, spending too much time chasing those weird permission denied errors and forgetting, that it is executed in /tmp
. It would be amazing if Yarn would detect this automatically.