.clojure.lein.swp: Permission denied error after trying to install Leiningen

.clojure.lein.swp: Permission denied error after trying to install Leiningen

对于我的一个 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 我应该首先做的,但完全忘记了我安装了自制软件。

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

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

以下是设置使用 lein 和 Clojure 的基本环境的步骤。在 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!

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