Ubuntu16.04 安装Leinigen

下载安装脚本

Leiningen是Clojure项目管理工具Leiningen is the easiest way to use Clojure

首先下载Leiningen安装脚本:https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein

百度云地址:

如果打不开,可见附录文件内容,脚本安装Leinigen版本为:2.8.1.

将其保存为lein文件,放置到/home/yitian/leiningen/lein目录,然后移动到/usr/bin/目录下面(Ubuntu16.0.4 LST 64Bit)

yitian@heron01:~$ sudo cp leiningen/lein /usr/bin/

修改文件权限:

sudo chmod +x lein 

安装Leinigen

使用非root用户,这里为yitian用户运行lein命令进行安装leinigen。运行lein时报错如下:

Image 1

解决方法为,在命令行中输入:

yitian@heron01:~$ export HTTP_CLIENT="wget --no-check-certificate -O"

然后进行安装,正常情况下是可以正常安装成功,但如果仍下载安装文件失败,则仍可能是网络问题(例如在一些网络被限制的地区),无奈只能自己寻求一些其他的解决方法了。。。

如果因为网络原因安装失败,删除掉~/.lein目录后重新执行lein命令即可:

yitian@heron01:~$ rm -rf .lein/

正常安装的命令如下:

yitian@heron01:~$ lein
WARNING: You have $CLASSPATH set, probably by accident.
It is strongly recommended to unset this before proceeding.
Downloading Leiningen to /home/yitian/.lein/self-installs/leiningen-2.8.1-standalone.jar now...
--2018-10-29 16:38:06--  https://github.com/technomancy/leiningen/releases/download/2.8.1/leiningen-2.8.1-standalone.zip
Resolving github.com (github.com)... 192.30.253.112, 192.30.253.113
Connecting to github.com (github.com)|192.30.253.112|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://github-production-release-asset-2e65be.s3.amazonaws.com/356756/57d8593a-bb24-11e7-9275-4464ed55c850?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20181029%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20181029T083808Z&X-Amz-Expires=300&X-Amz-Signature=478def0767c0d021b5b7f122e1503bf3e5c73a4716f2a359b6cc7bb250e452db&X-Amz-SignedHeaders=host&actor_id=0&response-content-disposition=attachment%3B%20filename%3Dleiningen-2.8.1-standalone.zip&response-content-type=application%2Foctet-stream [following]
--2018-10-29 16:38:08--  https://github-production-release-asset-2e65be.s3.amazonaws.com/356756/57d8593a-bb24-11e7-9275-4464ed55c850?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20181029%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20181029T083808Z&X-Amz-Expires=300&X-Amz-Signature=478def0767c0d021b5b7f122e1503bf3e5c73a4716f2a359b6cc7bb250e452db&X-Amz-SignedHeaders=host&actor_id=0&response-content-disposition=attachment%3B%20filename%3Dleiningen-2.8.1-standalone.zip&response-content-type=application%2Foctet-stream
Resolving github-production-release-asset-2e65be.s3.amazonaws.com (github-production-release-asset-2e65be.s3.amazonaws.com)... 52.216.20.251
Connecting to github-production-release-asset-2e65be.s3.amazonaws.com (github-production-release-asset-2e65be.s3.amazonaws.com)|52.216.20.251|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 13541128 (13M) [application/octet-stream]
Saving to: ‘/home/yitian/.lein/self-installs/leiningen-2.8.1-standalone.jar.pending’

/home/yitian/.lein/ 100%[===================>]  12.91M  30.1KB/s    in 5m 32s  

2018-10-29 16:43:43 (39.9 KB/s) - ‘/home/yitian/.lein/self-installs/leiningen-2.8.1-standalone.jar.pending’ saved [13541128/13541128]

Leiningen is a tool for working with Clojure projects.

Several tasks are available:
change              Rewrite project.clj by applying a function.
check               Check syntax and warn on reflection.
classpath           Print the classpath of the current project.
clean               Remove all files from project's target-path.
compile             Compile Clojure source into .class files.
deploy              Build and deploy jar to remote repository.
deps                Download all dependencies.
do                  Higher-order task to perform other tasks in succession.
help                Display a list of tasks or help for a given task.
install             Install the current project to the local repository.
jar                 Package up all the project's files into a jar file.
javac               Compile Java source files.
new                 Generate project scaffolding based on a template.
plugin              DEPRECATED. Please use the :user profile instead.
pom                 Write a pom.xml file to disk for Maven interoperability.
release             Perform :release-tasks.
repl                Start a repl session either with the current project or standalone.
retest              Run only the test namespaces which failed last time around.
run                 Run a -main function with optional command-line arguments.
search              Search Central and Clojars for published artifacts.
show-profiles       List all available profiles or display one if given an argument.
test                Run the project's tests.
trampoline          Run a task without nesting the project's JVM inside Leiningen's.
uberjar             Package up the project files and dependencies into a jar file.
update-in           Perform arbitrary transformations on your project map.
upgrade             Upgrade Leiningen to specified version or latest stable.
vcs                 Interact with the version control system.
version             Print version for Leiningen and the current JVM.
with-profile        Apply the given task with the profile(s) specified.

Run `lein help $TASK` for details.

Global Options:
  -o             Run a task offline.
  -U             Run a task after forcing update of snapshots.
  -h, --help     Print this help or help for a specific task.
  -v, --version  Print Leiningen's version.

These aliases are available:
downgrade, expands to upgrade

See also: readme, faq, tutorial, news, sample, profiles, deploying, gpg,
mixed-source, templates, and copying.

安装完成后,尝试运行lein repl进入控制台,命令如下:

yitian@heron01:~$ lein repl
WARNING: You have $CLASSPATH set, probably by accident.
It is strongly recommended to unset this before proceeding.
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 clojure-complete/clojure-complete/0.2.4/clojure-complete-0.2.4.jar from clojars
nREPL server started on port 43631 on host 127.0.0.1 - nrepl://127.0.0.1:43631

REPL-y 0.3.7, nREPL 0.2.12
Clojure 1.8.0
Java HotSpot(TM) 64-Bit Server VM 1.8.0_151-b12
    Docs: (doc function-name-here)
          (find-doc "part-of-name-here")
  Source: (source function-name-here)
 Javadoc: (javadoc java-object-or-class-here)
    Exit: Control+D or (exit) or (quit)
 Results: Stored in vars *1, *2, *3, an exception in *e

user=> 

user=> (println "heron, world!")
heron, world!
nil
user=> 

启动有时候稍微有些延迟,稍微等待完成后,输入heron, world,输出成功。注意=>左边的user代表当前的namespace。至此,leinigen安装成功。

参考文献

附录

Leinigen 2.8.1版本安装脚本内容:

#!/usr/bin/env bash



# Ensure this file is executable via `chmod a+x lein`, then place it

# somewhere on your $PATH, like ~/bin. The rest of Leiningen will be

# installed upon first run into the ~/.lein/self-installs directory.



export LEIN_VERSION="2.8.1"



case $LEIN_VERSION in

    *SNAPSHOT) SNAPSHOT="YES" ;;

    *) SNAPSHOT="NO" ;;

esac



if [[ "$CLASSPATH" != "" ]]; then

    echo "WARNING: You have \$CLASSPATH set, probably by accident."

    echo "It is strongly recommended to unset this before proceeding."

fi



if [[ "$OSTYPE" == "cygwin" ]] || [[ "$OSTYPE" == "msys" ]]; then

    delimiter=";"

else

    delimiter=":"

fi



if [[ "$OSTYPE" == "cygwin" ]]; then

  cygwin=true

else

  cygwin=false

fi



function command_not_found {

    >&2 echo "Leiningen couldn't find $1 in your \$PATH ($PATH), which is required."

    exit 1

}



function make_native_path {

    # ensure we have native paths

    if $cygwin && [[ "$1"  == /* ]]; then

    echo -n "$(cygpath -wp "$1")"

    elif [[ "$OSTYPE" == "msys" && "$1"  == /?/* ]]; then

    echo -n "$(sh -c "(cd $1 2</dev/null && pwd -W) || echo $1 | sed 's/^\\/\([a-z]\)/\\1:/g'")"

    else

    echo -n "$1"

    fi

}



#  usage : add_path PATH_VAR [PATH]...

function add_path {

    local path_var="$1"

    shift

    while [ -n "$1" ];do

        # http://bashify.com/?Useful_Techniques:Indirect_Variables:Indirect_Assignment

        if [[ -z ${!path_var} ]]; then

          export ${path_var}="$(make_native_path "$1")"

        else

          export ${path_var}="${!path_var}${delimiter}$(make_native_path "$1")"

        fi

    shift

    done

}



function download_failed_message {

    echo "Failed to download $1 (exit code $2)"

    echo "It's possible your HTTP client's certificate store does not have the"

    echo "correct certificate authority needed. This is often caused by an"

    echo "out-of-date version of libssl. It's also possible that you're behind a"

    echo "firewall and haven't set HTTP_PROXY and HTTPS_PROXY."

}



function self_install {

  if [ -r "$LEIN_JAR" ]; then

    echo "The self-install jar already exists at $LEIN_JAR."

    echo "If you wish to re-download, delete it and rerun \"$0 self-install\"."

    exit 1

  fi

  echo "Downloading Leiningen to $LEIN_JAR now..."

  mkdir -p "$(dirname "$LEIN_JAR")"

  LEIN_URL="https://github.com/technomancy/leiningen/releases/download/$LEIN_VERSION/leiningen-$LEIN_VERSION-standalone.zip"

  $HTTP_CLIENT "$LEIN_JAR.pending" "$LEIN_URL"

  local exit_code=$?

  if [ $exit_code == 0 ]; then

      # TODO: checksum

      mv -f "$LEIN_JAR.pending" "$LEIN_JAR"

  else

      rm "$LEIN_JAR.pending" 2> /dev/null

      download_failed_message "$LEIN_URL" "$exit_code"

      exit 1

  fi

}



NOT_FOUND=1

ORIGINAL_PWD="$PWD"

while [ ! -r "$PWD/project.clj" ] && [ "$PWD" != "/" ] && [ $NOT_FOUND -ne 0 ]

do

    cd ..

    if [ "$(dirname "$PWD")" = "/" ]; then

        NOT_FOUND=0

        cd "$ORIGINAL_PWD"

    fi

done



export LEIN_HOME="${LEIN_HOME:-"$HOME/.lein"}"



for f in "/etc/leinrc" "$LEIN_HOME/leinrc" ".leinrc"; do

  if [ -e "$f" ]; then

    source "$f"

  fi

done



if $cygwin; then

    export LEIN_HOME=$(cygpath -w "$LEIN_HOME")

fi



LEIN_JAR="$LEIN_HOME/self-installs/leiningen-$LEIN_VERSION-standalone.jar"



# normalize $0 on certain BSDs

if [ "$(dirname "$0")" = "." ]; then

    SCRIPT="$(which "$(basename "$0")")"

    if [ -z "$SCRIPT" ]; then

        SCRIPT="$0"

    fi

else

    SCRIPT="$0"

fi



# resolve symlinks to the script itself portably

while [ -h "$SCRIPT" ] ; do

    ls=$(ls -ld "$SCRIPT")

    link=$(expr "$ls" : '.*-> \(.*\)$')

    if expr "$link" : '/.*' > /dev/null; then

        SCRIPT="$link"

    else

        SCRIPT="$(dirname "$SCRIPT"$)/$link"

    fi

done



BIN_DIR="$(dirname "$SCRIPT")"



export LEIN_JVM_OPTS="${LEIN_JVM_OPTS-"-Xverify:none -XX:+TieredCompilation -XX:TieredStopAtLevel=1"}"



# This needs to be defined before we call HTTP_CLIENT below

if [ "$HTTP_CLIENT" = "" ]; then

    if type -p curl >/dev/null 2>&1; then

        if [ "$https_proxy" != "" ]; then

            CURL_PROXY="-x $https_proxy"

        fi

        HTTP_CLIENT="curl $CURL_PROXY -f -L -o"

    else

        HTTP_CLIENT="wget -O"

    fi

fi





# When :eval-in :classloader we need more memory

grep -E -q '^\s*:eval-in\s+:classloader\s*$' project.clj 2> /dev/null && \

    export LEIN_JVM_OPTS="$LEIN_JVM_OPTS -Xms64m -Xmx512m"



if [ -r "$BIN_DIR/../src/leiningen/version.clj" ]; then

    # Running from source checkout

    LEIN_DIR="$(dirname "$BIN_DIR")"



    # Need to use lein release to bootstrap the leiningen-core library (for aether)

    if [ ! -r "$LEIN_DIR/leiningen-core/.lein-bootstrap" ]; then

        echo "Leiningen is missing its dependencies."

        echo "Please run \"lein bootstrap\" in the leiningen-core/ directory"

        echo "with a stable release of Leiningen. See CONTRIBUTING.md for details."

        exit 1

    fi



    # If project.clj for lein or leiningen-core changes, we must recalculate

    LAST_PROJECT_CHECKSUM=$(cat "$LEIN_DIR/.lein-project-checksum" 2> /dev/null)

    PROJECT_CHECKSUM=$(sum "$LEIN_DIR/project.clj" "$LEIN_DIR/leiningen-core/project.clj")

    if [ "$PROJECT_CHECKSUM" != "$LAST_PROJECT_CHECKSUM" ]; then

        if [ -r "$LEIN_DIR/.lein-classpath" ]; then

            rm "$LEIN_DIR/.lein-classpath"

        fi

    fi



    # Use bin/lein to calculate its own classpath.

    if [ ! -r "$LEIN_DIR/.lein-classpath" ] && [ "$1" != "classpath" ]; then

        echo "Recalculating Leiningen's classpath."

        ORIG_PWD="$PWD"

        cd "$LEIN_DIR"



        LEIN_NO_USER_PROFILES=1 $0 classpath .lein-classpath

        sum "$LEIN_DIR/project.clj" "$LEIN_DIR/leiningen-core/project.clj" > \

            .lein-project-checksum

        cd "$ORIG_PWD"

    fi



    mkdir -p "$LEIN_DIR/target/classes"

    export LEIN_JVM_OPTS="$LEIN_JVM_OPTS -Dclojure.compile.path=$LEIN_DIR/target/classes"

    add_path CLASSPATH "$LEIN_DIR/leiningen-core/src/" "$LEIN_DIR/leiningen-core/resources/" \

        "$LEIN_DIR/test:$LEIN_DIR/target/classes" "$LEIN_DIR/src" ":$LEIN_DIR/resources"



    if [ -r "$LEIN_DIR/.lein-classpath" ]; then

        add_path CLASSPATH "$(cat "$LEIN_DIR/.lein-classpath" 2> /dev/null)"

    else

        add_path CLASSPATH "$(cat "$LEIN_DIR/leiningen-core/.lein-bootstrap" 2> /dev/null)"

    fi

else # Not running from a checkout

    add_path CLASSPATH "$LEIN_JAR"



    if [ "$LEIN_USE_BOOTCLASSPATH" != "" ]; then

        LEIN_JVM_OPTS="-Xbootclasspath/a:$LEIN_JAR $LEIN_JVM_OPTS"

    fi



    if [ ! -r "$LEIN_JAR" -a "$1" != "self-install" ]; then

        self_install

    fi

fi



if [ ! -x "$JAVA_CMD" ] && ! type -f java >/dev/null

then

    >&2 echo "Leiningen couldn't find 'java' executable, which is required."

    >&2 echo "Please either set JAVA_CMD or put java (>=1.6) in your \$PATH ($PATH)."

    exit 1

fi



export LEIN_JAVA_CMD="${LEIN_JAVA_CMD:-${JAVA_CMD:-java}}"



if [[ -z "${DRIP_INIT+x}" && "$(basename "$LEIN_JAVA_CMD")" == *drip* ]]; then

    export DRIP_INIT="$(printf -- '-e\n(require (quote leiningen.repl))')"

    export DRIP_INIT_CLASS="clojure.main"

fi



# Support $JAVA_OPTS for backwards-compatibility.

export JVM_OPTS="${JVM_OPTS:-"$JAVA_OPTS"}"



# Handle jline issue with cygwin not propagating OSTYPE through java subprocesses: https://github.com/jline/jline2/issues/62

cygterm=false

if $cygwin; then

  case "$TERM" in

    rxvt* | xterm* | vt*) cygterm=true ;;

  esac

fi



if $cygterm; then

  LEIN_JVM_OPTS="$LEIN_JVM_OPTS -Djline.terminal=jline.UnixTerminal"

  stty -icanon min 1 -echo > /dev/null 2>&1

fi



# TODO: investigate http://skife.org/java/unix/2011/06/20/really_executable_jars.html

# If you're packaging this for a package manager (.deb, homebrew, etc)

# you need to remove the self-install and upgrade functionality or see lein-pkg.

if [ "$1" = "self-install" ]; then

    if [ -r "$BIN_DIR/../src/leiningen/version.clj" ]; then

        echo "Running self-install from a checkout is not supported."

        echo "See CONTRIBUTING.md for SNAPSHOT-specific build instructions."

        exit 1

    fi

    echo "Manual self-install is deprecated; it will run automatically when necessary."

    self_install

elif [ "$1" = "upgrade" ] || [ "$1" = "downgrade" ]; then

    if [ "$LEIN_DIR" != "" ]; then

        echo "The upgrade task is not meant to be run from a checkout."

        exit 1

    fi

    if [ $SNAPSHOT = "YES" ]; then

        echo "The upgrade task is only meant for stable releases."

        echo "See the \"Bootstrapping\" section of CONTRIBUTING.md."

        exit 1

    fi

    if [ ! -w "$SCRIPT" ]; then

        echo "You do not have permission to upgrade the installation in $SCRIPT"

        exit 1

    else

        TARGET_VERSION="${2:-stable}"

        echo "The script at $SCRIPT will be upgraded to the latest $TARGET_VERSION version."

        echo -n "Do you want to continue [Y/n]? "

        read RESP

        case "$RESP" in

            y|Y|"")

                echo

                echo "Upgrading..."

                TARGET="/tmp/lein-${$}-upgrade"

                if $cygwin; then

                    TARGET=$(cygpath -w "$TARGET")

                fi

                LEIN_SCRIPT_URL="https://github.com/technomancy/leiningen/raw/$TARGET_VERSION/bin/lein"

                $HTTP_CLIENT "$TARGET" "$LEIN_SCRIPT_URL"

                if [ $? == 0 ]; then

                    cmp -s "$TARGET" "$SCRIPT"

                    if [ $? == 0 ]; then

                        echo "Leiningen is already up-to-date."

                    fi

                    mv "$TARGET" "$SCRIPT" && chmod +x "$SCRIPT"

                    exec "$SCRIPT" version

                else

                    download_failed_message "$LEIN_SCRIPT_URL"

                fi;;

            *)

                echo "Aborted."

                exit 1;;

        esac

    fi

else

    if $cygwin; then

        # When running on Cygwin, use Windows-style paths for java

        ORIGINAL_PWD=$(cygpath -w "$ORIGINAL_PWD")

    fi



    # apply context specific CLASSPATH entries

    if [ -f .lein-classpath ]; then

        add_path CLASSPATH "$(cat .lein-classpath)"

    fi



    if [ -n "$DEBUG" ]; then

        echo "Leiningen's classpath: $CLASSPATH"

    fi



    if [ -r .lein-fast-trampoline ]; then

        export LEIN_FAST_TRAMPOLINE='y'

    fi



    if [ "$LEIN_FAST_TRAMPOLINE" != "" ] && [ -r project.clj ]; then

        INPUTS="$* $(cat project.clj) $LEIN_VERSION $(test -f "$LEIN_HOME/profiles.clj" && cat "$LEIN_HOME/profiles.clj")"



        if command -v shasum >/dev/null 2>&1; then

            SUM="shasum"

        elif command -v sha1sum >/dev/null 2>&1; then

            SUM="sha1sum"

        else

            command_not_found "sha1sum or shasum"

        fi



        export INPUT_CHECKSUM=$(echo "$INPUTS" | $SUM | cut -f 1 -d " ")

        # Just don't change :target-path in project.clj, mkay?

        TRAMPOLINE_FILE="target/trampolines/$INPUT_CHECKSUM"

    else

        if hash mktemp 2>/dev/null; then

            # Check if mktemp is available before using it

            TRAMPOLINE_FILE="$(mktemp /tmp/lein-trampoline-XXXXXXXXXXXXX)"

        else

            TRAMPOLINE_FILE="/tmp/lein-trampoline-$$"

        fi

        trap 'rm -f $TRAMPOLINE_FILE' EXIT

    fi



    if $cygwin; then

        TRAMPOLINE_FILE=$(cygpath -w "$TRAMPOLINE_FILE")

    fi



    if [ "$INPUT_CHECKSUM" != "" ] && [ -r "$TRAMPOLINE_FILE" ]; then

        if [ -n "$DEBUG" ]; then

            echo "Fast trampoline with $TRAMPOLINE_FILE."

        fi

        exec sh -c "exec $(cat "$TRAMPOLINE_FILE")"

    else

        export TRAMPOLINE_FILE

        "$LEIN_JAVA_CMD" \

            -Dfile.encoding=UTF-8 \

            -Dmaven.wagon.http.ssl.easy=false \

            -Dmaven.wagon.rto=10000 \

            $LEIN_JVM_OPTS \

            -Dleiningen.original.pwd="$ORIGINAL_PWD" \

            -Dleiningen.script="$SCRIPT" \

            -classpath "$CLASSPATH" \

            clojure.main -m leiningen.core.main "$@"



        EXIT_CODE=$?



        if $cygterm ; then

          stty icanon echo > /dev/null 2>&1

        fi



        if [ -r "$TRAMPOLINE_FILE" ] && [ "$LEIN_TRAMPOLINE_WARMUP" = "" ]; then

            TRAMPOLINE="$(cat "$TRAMPOLINE_FILE")"

            if [ "$INPUT_CHECKSUM" = "" ]; then # not using fast trampoline

                rm "$TRAMPOLINE_FILE"

            fi

            if [ "$TRAMPOLINE" = "" ]; then

                exit $EXIT_CODE

            else

                exec sh -c "exec $TRAMPOLINE"

            fi

        else

            exit $EXIT_CODE

        fi

    fi

fi