【问题标题】:.clojure.lein.swp: Permission denied error after trying to install Leiningen.clojure.lein.swp:尝试安装 Leiningen 后权限被拒绝错误
【发布时间】:2017-02-28 10:23:02
【问题描述】:

对于我的一门 CS 课程,我们正在学习 Clojure,为了做到这一点,我们当然需要设置我们的计算机,以便它们可以运行 Clojure。我的教授的指示如下:

“如果您想要一个不错的 Clojure IDE,我推荐以下内容:

  1. 安装 Java 开发工具包 (JDK) 最新版本

  2. 安装 Leiningen:leiningen.org

  3. 安装 IntelliJ IDEA。安装后,安装 Clojure 语法高亮的“Cursive”插件。”

首先,如果这对我有帮助的话,我在 macOS Sierra 上。我已经安装了JDK,所以我直接进入第二步:安装leiningen。根据网站上列出的安装 leiningen 的说明,我下载了 lein 脚本,并将其移至 ~/bin。然后我尝试了chmod a+x ~/bin/lein,它并没有真正做任何事情,或者至少我没有被告知它做了任何事情。

leiningen.org 的下一步是运行脚本,所以我使用了运行的 ./lein,但是当我在终端中输入 lein 时,终端提示我:-bash: /usr/local/bin/lein: No such file or directory。然后我尝试了很多不同的方法来尝试让 lein 工作,但最后我最终使用了 brew install leiningen,我应该首先这样做,但完全忘记了我安装了自制软件。

我真的不记得这是什么时候开始发生的,但每次我打开一个新的终端窗口时都会受到欢迎:

Last login: Tue Oct 18 16:46:04 on ttys000
.clojure.lein.swp: Permission denied
Michaels-MacBook-Air:~ Michael$

终端似乎仍然可以正常工作,但.clojure.lein.swp: Permission denied 真的很困扰我,我不知道如何解决它。我试过卸载 leiningen,但似乎没有用。如果它有帮助,这是我试图让 leiningen 工作时的终端历史:

389  cd /Users/Michael/Documents/
390  chmod a+x ~/bin/lein
391  chmod a+x ~/bin/lein.txt
392  chmod a+x /lein
393  chmod a+x ~ /lein
394  chmod a+x ~/lein
395  chmod a+x ~/Documents/lein
396  chmod a+x ~/Documents/lein.txt
397  ./lein
398  cd ~/bin
399  cd bin
400  ls
401  chmod a+x ~/Documents/lein.txt
402  chmod a+x ~/Documents/lein
403  lein
404  cd ~
405  pwd
406  (chmod a+x ~/lein)
407  (chmod a+x ~/lein.txt)
408  lein.txt
409  ./lein.txt
410  lein -version
411  lein help $TASK
412  lein
413  lein new app my-stuff
414  -o
415  ./lein
416  ./lein.txt
417  lein help
418  lein help $TASK
419  echo $PATH
420  (chmod a+x ~/lein)
421  lein
422  $echo $PATH
423  cd /bin
424  pwd
425  cd /usr/local/bin/
426  chmod a+x ~/bin/lein
427  chmod a+x /usr/local/bin/lein.txt
428  ./lein.txt
429  lein
430  lein
431  lein self-install
432  .//Users/Michael/.lein/self-installs/leiningen-2.7.1-standalone.jar
433  cd /Users/Michael/.lein/self-installs/
434  pwd
435  ls
436  ./leiningen-2.7.1-standalone.jar
437  sudo ./leiningen-2.7.1-standalone.jar
438  lein
439  echo $PATH
440  mkdr /Applications/clojure
441  mkdir /Applications/clojure
442  cd /Applications/clojure
443  sudo curl-o
444  sudo curl-O
445  sudo curl -O https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein
446  sudo chmod a+x lein
447  cd /etc/paths.d/
448  sudo vi clojure.lein
449  echo $PATH
450  sudo vi clojure.lein
451  echo $PATH
452  lein
453  lein repl

【问题讨论】:

  • 似乎问题与所有权有关,chown 会有所帮助(但可能不推荐)。拥有您尝试运行的命令的用户是什么?授予其他用户什么权限?

标签: macos intellij-idea clojure terminal leiningen


【解决方案1】:

从您的 shell 命令历史来看,您一直在以 root (sudo vi clojure.lein) 身份编辑 clojure.lein 文件。关闭vi 并删除.clojure.lein.swp 文件(如果存在)(以root 身份使用sudo)。

【讨论】:

  • 谢谢!我不得不回到 /etc/paths.d 文件夹并删除 clojure.lein.swp 文件,这解决了我的问题。
【解决方案2】:

以下是设置基本环境以在 Clojure 中使用 lein 的步骤。为 Ubuntu linux 上的新用户帐户执行。在 OSX 上应该差不多:

# Create a new user and login to the new account
> sudo adduser cljuser
Adding user `cljuser'
<snip>
~/cool/notes > sudo su - cljuser

# Starting with a new, empty user account.  Define a useful alias
cljuser@brandy:~$ alias d="ls -ldF"

# Display where I have java installed on this computer
cljuser@brandy:~$ d /opt/*
lrwxrwxrwx  1 root root   11 Feb  1  2016 /opt/java -> jdk1.8.0_72/
drwxr-xr-x  8 alan alan 4096 Dec 22  2015 /opt/jdk1.8.0_72/

# Set up env var for java, and augment the path to find the java executable file
cljuser@brandy:~$ export JAVA_HOME=/opt/java
cljuser@brandy:~$ export PATH=${JAVA_HOME}/bin:${PATH} 
cljuser@brandy:~$ java -version
java version "1.8.0_72"
Java(TM) SE Runtime Environment (build 1.8.0_72-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.72-b15, mixed mode)

# We will install the lein shell script launcher in ~/bin
cljuser@brandy:~$ mkdir ~/bin
cljuser@brandy:~$ d ~/bin
drwxrwxr-x 2 cljuser cljuser 4096 Oct 18 20:16 /home/cljuser/bin/
cljuser@brandy:~$ cd bin
cljuser@brandy:~/bin$ curl https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein > lein
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 12871  100 12871    0     0  48805      0 --:--:-- --:--:-- --:--:-- 48939

# We have the script, but need to make it executable
cljuser@brandy:~/bin$ d *
-rw-rw-r-- 1 cljuser cljuser 12871 Oct 18 20:16 lein
cljuser@brandy:~/bin$ chmod a+x lein 
cljuser@brandy:~/bin$ d *
-rwxrwxr-x 1 cljuser cljuser 12871 Oct 18 20:16 lein*

# Update to path so lein will run from any location
cljuser@brandy:~/bin$ cd
cljuser@brandy:~$ export PATH=~/bin:${PATH} 
cljuser@brandy:~$ which lein
/home/cljuser/bin/lein

# First time downloads the actual "lein" executable. 2nd & later runs skip the download
cljuser@brandy:~$ lein --version
Downloading Leiningen to /home/cljuser/.lein/self-installs/leiningen-2.7.1-standalone.jar now...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   605    0   605    0     0    928      0 --:--:-- --:--:-- --:--:--   927
100 14.6M  100 14.6M    0     0  1583k      0  0:00:09  0:00:09 --:--:-- 2015k
Leiningen 2.7.1 on Java 1.8.0_72 Java HotSpot(TM) 64-Bit Server VM
cljuser@brandy:~$ lein --version
Leiningen 2.7.1 on Java 1.8.0_72 Java HotSpot(TM) 64-Bit Server VM

# We are in the home dir, but we could still run lein
cljuser@brandy:~$ d *
drwxrwxr-x 2 cljuser cljuser 4096 Oct 18 20:16 bin/
-rw-r--r-- 1 cljuser cljuser 8980 Oct 18 20:13 examples.desktop

# create a new Clojure project named "sample" and run it
cljuser@brandy:~$ lein new app sample
Generating a project called sample based on the 'app' template.
cljuser@brandy:~$ cd sample

# first run downloads some *.jar files
cljuser@brandy:~/sample$ lein run
Retrieving org/clojure/clojure/1.8.0/clojure-1.8.0.pom from central
Retrieving org/sonatype/oss/oss-parent/7/oss-parent-7.pom from central
Retrieving org/clojure/tools.nrepl/0.2.12/tools.nrepl-0.2.12.pom from central
Retrieving org/clojure/pom.contrib/0.1.2/pom.contrib-0.1.2.pom from central
Retrieving clojure-complete/clojure-complete/0.2.4/clojure-complete-0.2.4.pom from clojars
Retrieving org/clojure/tools.nrepl/0.2.12/tools.nrepl-0.2.12.jar from central
Retrieving org/clojure/clojure/1.8.0/clojure-1.8.0.jar from central
Retrieving clojure-complete/clojure-complete/0.2.4/clojure-complete-0.2.4.jar from clojars
Hello, World!

# 2nd & later runs skip download
cljuser@brandy:~/sample$ lein run
Hello, World!

# All finished! Enjoy!

【讨论】:

  • 谢谢!我最终使用 home-brew 来做,因为它很简单,但如果其他学生在安装 Leiningen 时遇到问题,我一定会把他们推荐给你的指南。
猜你喜欢
  • 1970-01-01
  • 2018-10-09
  • 2018-11-14
  • 1970-01-01
  • 2016-06-27
  • 2018-02-18
  • 2016-02-21
  • 2020-05-01
相关资源
最近更新 更多