Sublime Text Permission Denied: Fix It Step by Step
In this article
If Sublime Text shows a "permission denied" error, it usually means the app cannot write to a file or folder it needs to access. This can happen when opening a file owned by another user, saving to a protected system directory, or when the app lacks the necessary file permissions. The fix depends on the situation, but the most common solutions are to change file ownership, adjust folder permissions, or run Sublime Text with the correct user account. Below is a step-by-step guide to resolve the error.
What You'll Need
- Access to a terminal or command prompt (on macOS/Linux) or Command Prompt/PowerShell (on Windows).
- Administrator or sudo privileges (you'll be prompted for a password).
- The path to the file or folder that's causing the error.
Step-by-Step
- Identify the exact file or folder. The error message usually includes the path. If not, try to save the file again and note the path in the dialog. For example, it might be
/etc/hostsorC:\Program Files\SomeFolder\file.txt. - Check current permissions (macOS/Linux). Open Terminal and run:
ls -l /path/to/file. This shows the owner and permissions. If the owner isrootand you're not root, that's the problem. On Windows, right-click the file > Properties > Security tab to see permissions. - If you're trying to edit a system file (like /etc/hosts or a file in Program Files), don't change permissions. Instead, open Sublime Text with elevated privileges. On macOS/Linux, run
sudo subl /path/to/file(orsudo sublime_text). On Windows, right-click Sublime Text and choose "Run as administrator" (but note: this is generally discouraged for daily use; better to copy the file to your user directory and edit there). - If the file is in your own user folder but still gives permission denied, the file might be owned by another user (e.g., after copying from another drive). On macOS/Linux, run
sudo chown $(whoami) /path/to/fileto take ownership. On Windows, go to Properties > Security > Advanced > Change owner, and set it to your user. - If you're saving to a folder that doesn't allow writing, change the folder's permissions. For example, on macOS/Linux, to allow your user to write to a folder:
sudo chown -R $(whoami) /path/to/folder. On Windows, right-click the folder > Properties > Security > Edit, and give your user "Full control". - If the error occurs when Sublime Text tries to create a temporary file or cache, check the Sublime Text cache folder permissions. On macOS/Linux, that's
~/.config/sublime-text/(or~/.cache/sublime-text/). On Windows, it's%APPDATA%\Sublime Text\. Ensure your user has read/write access to those folders. If not, delete them (Sublime will recreate them) after closing Sublime, or change permissions. - If you're using a network drive or external storage, the permission issue may be on the server or device. Check if you can write to that location from the file explorer. If not, contact the network administrator or check the device's sharing settings.
- After making changes, restart Sublime Text and try again.
Common Mistakes
- Changing permissions of system files to your user, which can break system security. Avoid editing system files directly; use sudo or copy to your home directory.
- Using
sudoto open Sublime Text and then saving files as root, which creates files that you can't edit later without sudo. - Forgetting to close and reopen Sublime Text after changing permissions.
- On Windows, running as administrator for all tasks, which can cause permission issues for other apps and is a security risk.
Tips
- If you frequently need to edit system files, consider using a dedicated editor with a plugin that handles sudo, or use the terminal with nano/vim.
- On macOS, you can use the "Open" dialog in Sublime Text to navigate to the file and press Cmd+Shift+G to go to folder, then type the path.
- On Linux, you can use the file manager to right-click and select "Open as Administrator" if available.
- Keep your Sublime Text updated; sometimes permission errors are fixed in newer versions.
Troubleshooting
If the steps above don't resolve the issue:
- Check if the file is read-only. On macOS/Linux, run
ls -land look forr--(no write). On Windows, check the "Read-only" attribute in Properties. If it's read-only, uncheck it or change permissions. - Try saving to a different location. If that works, the issue is with the original folder. Copy the file to your home directory, edit it there, and then copy it back (with sudo if needed).
- Check if the file is locked by another process. On Windows, close any program that might be using the file. On macOS/Linux, use
lsof /path/to/fileto see which process has it open. - If you're using a package or plugin that writes to a specific folder, that folder might have incorrect permissions. Look in Sublime Text's console (View > Show Console) for the exact path.
- If all else fails, reinstall Sublime Text. Uninstall, then reinstall from the official website. This resets any corrupted settings or permissions.
Frequently Asked Questions
Why does Sublime Text say "Permission denied" when I try to save a file?
This usually means the file or the folder it's in doesn't allow your user account to write. Check the file's permissions and ownership, and change them if they're wrong.
Can I just run Sublime Text as administrator to fix this?
On Windows, you can, but it's not recommended because it can cause other issues and is a security risk. Better to fix the folder permissions properly.
How do I change file ownership on macOS?
Use the terminal command sudo chown yourusername /path/to/file. Replace yourusername with your macOS username.
What if the error occurs when opening a file from a USB drive?
USB drives often have a filesystem that doesn't support Unix permissions (like FAT32). Try copying the file to your computer's hard drive first, edit it there, then copy it back.
I get "Permission denied" when Sublime Text tries to auto-update. What should I do?
This is often due to the Sublime Text installation folder being write-protected. On Windows, install Sublime Text in your user folder (e.g., C:\Users\YourName\AppData\Local\Programs\) instead of Program Files. On macOS, move the app from the read-only system volume to your Applications folder if it's not already there.
Is it safe to use sudo to open Sublime Text?
It's safe for a one-time edit, but it can create files owned by root, which you'll later need sudo to edit. Prefer changing the file's ownership or copying the file to your home directory.