1
votes

For one of my CS classes we're learning about Clojure and in order to do so, we of course need to set up our computers so that they can run Clojure. My professor's instructions were as follows:

"If you would like a nice IDE for Clojure, I recommend the following:

  1. Install the Java Development Kit (JDK) newest version

  2. Install Leiningen: leiningen.org

  3. Install IntelliJ IDEA. When installed, install the "Cursive" plugin for Clojure syntax highlighting."

Firstly, if this helps at all I am on macOS Sierra. I already have the JDK installed, so I went straight to the second step: installing leiningen. Per the instructions listed on the site for installing leiningen, I downloaded the lein script, and moved it to ~/bin. I then tried chmod a+x ~/bin/lein which didn't really do anything, or at least I wasn't informed that it did anything.

The next step on leiningen.org was to run the script, so I used ./lein which ran, but when I entered lein into the terminal the terminal prompted me with: -bash: /usr/local/bin/lein: No such file or directory. I then tried a bunch of different things to try to get lein to work but in the end I ended up using brew install leiningen which I should have done in the first place, but totally forgot that I had homebrew installed.

I don't really remember when this started happening but every time I open up a new terminal window I'm greeted with:

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

Terminal still seems to work perfectly fine, but the .clojure.lein.swp: Permission denied is really bothering me, and I can't figure out how to fix it. I've tried uninstalling leiningen but it didn't seem to work. If it helps at all, here is my terminal history from when I was trying to get leiningen to work:

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
2
Seems like the problem is about ownership and chown will help (however might not be recommended). What is the user that owns the command you are trying to run? What are the permissions given to other users? - Chris Murphy

2 Answers

1
votes

From your shell commands history it looks you have been editing clojure.lein file as root (sudo vi clojure.lein). Close vi and remove .clojure.lein.swp file if it exists (as root using sudo).

0
votes

Here are the steps to set up a basic environment for using lein with Clojure. Executed for a fresh user account on Ubuntu linux. It should be about the same on 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!