无法在Mac OS Catalina上编辑.profile。

huangapple go评论83阅读模式
英文:

Cannot edit .profile on Mac OS Catalina

问题

我想在Mac的/etc文件夹中的.profile中声明$JAVA_HOME。我使用chmod 777 profile赋予了它权限,但它仍然不允许我进行编辑。

我对在Mac上进行开发还不熟悉。

以下是我收到的错误信息:

英文:

I wanted to declare $JAVA_HOME in .profile in /etc folder for Mac. I gave it permission using chmod 777 profile still it doesn't let me edit it.

I am new to development in mac.

Following is the error I get

无法在Mac OS Catalina上编辑.profile。

答案1

得分: 2

尝试从您的用户中编辑.profile文件,而不是在/etc目录下编辑(要编辑后者,您需要sudo权限,即使您编辑了它,很可能也不会被正确读取)。

因此,作为常规用户(非sudo),打开您的用户中的.profile文件。使用open命令(如您的屏幕截图中所示,但我更推荐选择vim)。以下其中一个命令应该有效:

open ~/.profile

或者

open /Users/${your-username}/.profile

我猜${your-username}divya,所以完整的路径应该是:

open /Users/divya/.profile

如果您收到错误消息说“文件/.../.profile不存在”,首先创建一个空文件:

touch ~./profile

.profile文件中添加以下行:

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home

(确保使用安装在您的机器上的Java版本)

然后,要使更改生效,重新启动终端窗口,或者输入:

source ~/.profile

为了验证是否正确设置了$JAVA_HOME

echo $JAVA_HOME

接着输入:

java -version
英文:

Try to edit the .profile from your user, and not the one under /etc (to edit that one you need sudo rights, and even if you do edit it, most probably it won't be read correctly).

So, as a regular user (not sudo), open the one from your user. Using open (as in your screenshot, but I would rather choose vim). One of the below commands should work:

open ~/.profile

or

open /Users/${your-username}/.profile

I guess ${your-username} is divya, so the complete path would be:

open /Users/divya/.profile

If you get an error saying The File /.../.profile does not exist, first create an empty one:

touch ~./profile

Add in the .profile file, the following line:

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home

(make sure to use the Java version installed on your machine)

Then, for the changes to take place, either restart your terminal window, or type:

source ~/.profile

And to validate that you've set the $JAVA_HOME correctly:

echo $JAVA_HOME

Followed by:

java -version

huangapple
  • 本文由 发表于 2020年4月8日 22:51:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/61103613.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定