You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CentOS7下Sublime Text3保存Java文件提示权限拒绝问题求助

Fixing "Permission Denied" When Saving Java Files in Sublime Text 3 on CentOS 7

Hey there! Let's work through this issue together. First, I spotted a couple of critical typos in your Java code that'll cause errors even after fixing the permission problem—let's get those out of the way first, then tackle the saving issue.

Step 1: Fix Your Java Code

Java is case-sensitive, so these two mistakes will prevent your code from compiling:

  • string should be uppercase String (the official Java class name)
  • system.out.println should be System.out.println (the standard output class is capitalized)

Here's the corrected code:

package com.javatools.git;

public class FirstSource {
    public static void main(String[] args) {
        System.out.println("Hello World");
    }
}

Step 2: Resolve the "Permission Denied" Error

The error means Sublime Text doesn't have write access to the ~/git_tutorial/git_repo/ directory. Try these solutions in order:

Option 1: Grant Write Permissions to the Directory

Give your user account write access to the target folder with this terminal command:

chmod -R u+w ~/git_tutorial/git_repo/
  • u+w: Adds write permission specifically for your user account
  • -R: Applies the change recursively to all files and subfolders inside the directory

Option 2: Change the Directory's Owner (If Needed)

If the directory was created by another user (like root), change its owner to your user account to gain full control:

sudo chown -R $USER:$USER ~/git_tutorial/git_repo/

This ensures you can read, write, and modify anything inside the folder.

Option 3: Temporary Fix (Use Sudo to Open Sublime)

For a quick temporary solution (not recommended for regular use, as it can cause permission conflicts), open Sublime with root privileges:

sudo subl

Then save your file from this elevated instance of Sublime.

Once you've fixed the permissions and the code, you should be able to save the file successfully and compile your first Java program!

内容的提问来源于stack exchange,提问作者bbjoony

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 08:14:32