yarnpkg/yarn · error · MessageError
noPermission
Error message
noPermission
What it means
During global install/update, `initUpdateBins` creates the global `bin` folder and links binaries. `throwPermError` (`global.js:132`) inspects caught filesystem errors and, when `err.code === 'EACCES'`, rethrows `noPermission` with the failing path. EACCES means the OS denied create/write to that path.
Source
Thrown at src/cli/commands/global.js:132
return FALLBACK_GLOBAL_PREFIX;
}
return prefix;
}
export async function getBinFolder(config: Config, flags: Object): Promise<string> {
const prefix = await getGlobalPrefix(config, flags);
return path.resolve(prefix, 'bin');
}
async function initUpdateBins(config: Config, reporter: Reporter, flags: Object): Promise<() => Promise<void>> {
const beforeBins = await getBins(config);
const binFolder = await getBinFolder(config, flags);
function throwPermError(err: Error & {[code: string]: string}, dest: string) {
if (err.code === 'EACCES') {
throw new MessageError(reporter.lang('noPermission', dest));
} else {
throw err;
}
}
return async function(): Promise<void> {
try {
await fs.mkdirp(binFolder);
} catch (err) {
throwPermError(err, binFolder);
}
const afterBins = await getBins(config);
// remove old bins
for (const src of beforeBins) {
if (afterBins.has(src)) {
// not oldView on GitHub (pinned to c2dda503f3)
Solutions
- Reconfigure the global prefix to a user-writable dir: `yarn config set prefix ~/.yarn-global`.
- Fix ownership: `sudo chown -R $(whoami) <prefix>`.
- Avoid `sudo yarn global add` (it root-owns files and worsens the problem).
- Use a node version manager (nvm) so the prefix is under your home dir.
Example fix
// before $ yarn global add prettier → Cannot create /usr/local/bin due to insufficient permissions. // after $ yarn config set prefix ~/.yarn-global $ yarn global add prettier
Defensive patterns
Strategy: validation
Validate before calling
import fs from 'fs';
function assertWritableBinFolder(binFolder: string): void {
try {
fs.accessSync(binFolder, fs.constants.W_OK);
} catch {
throw new Error(`${binFolder} is not writable by ${process.env.USER}; set yarn prefix to a user-owned dir`);
}
} Try / catch
try {
await yarnGlobalAdd(pkg);
} catch (e) {
if (/insufficient permissions/.test(e.message)) {
await reconfigurePrefixToUserDir(); // yarn config set prefix ~/.yarn-global
await yarnGlobalAdd(pkg);
} else throw e;
} Prevention
- Set a user-owned `prefix` once: `yarn config set prefix ~/.yarn-global`.
- Never use `sudo yarn global add`; it root-owns future files.
- Use nvm/nodenv so node's prefix lives under your home directory.
When it happens
Trigger: An `EACCES` filesystem error on the global prefix or bin folder — typically `fs.mkdirp(binFolder)` or a subsequent symlink/write fails because the directory is owned by root/another user.
Common situations: Default global prefix resolves to `/usr/local/bin` (system-owned); the user ran without sudo but the dir is not writable; previous `sudo yarn global add` changed ownership of `~/.config`/`~/.local`.
Related errors
- Yarn hasn't been able to find a cache folder it can use. Ple
- linkMissing
- Don't know how to handle this file type
- unknownFolderOrTarball
- linkMissing
AI-assisted analysis of yarnpkg/yarn@c2dda503f3 (2026-08-13).
Data as JSON: /api/errors/30b8f5ff9a4c1247.
Report an issue: GitHub.