Application Development
RSS feed
  • Windows 10 and lein self-install fails on Powershell – Solved

    I am starting to learn Clojure and wanted to set up Leiningen on my Windows 10 professional.

    Here is how I solved the Windows Security problem that was preventing me from downloading the github zip file needed.

    Here is hoping that someone finds this solution helpful.

    Using PowerShell running as Administrator, I was having trouble getting my REPL going:

    PS C:\> lein repl

    C:\Users\{YourUserName}\.lein\self-installs\leiningen-2.8.1-standalone.jar can not be found.
    You can try running "lein self-install"
    or change LEIN_JAR environment variable
    or edit lein.bat to set appropriate LEIN_JAR path.

    Next, I tried to command lein to self-install:

    PS C:\> lein self-install
    Downloading Leiningen now...
    Exception calling "DownloadFile" with "2" argument(s): "The request was aborted: Could not create SSL/TLS secure
    channel."
    At line:1 char:145
    + ... che]::DefaultNetworkCredentials; $client.DownloadFile($a, $f)} "https ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : WebException

    Failed to download https://github.com/technomancy/leiningen/releases/download/2.8.1/leiningen-2.8.1-standalone.zip

    It is possible that the download failed due to "powershell",
    "curl" or "wget"'s inability to retrieve GitHub's security certificate.
    The suggestions below do not check certificates, so use this only if
    you understand the security implications of not doing so.

    The PowerShell failed to download the latest Leiningen version.
    Try to use "curl" or "wget" to download Leiningen by setting up
    the HTTP_CLIENT environment variable with one of the following
    values:

    a) set HTTP_CLIENT=wget --no-check-certificate -O
    b) set HTTP_CLIENT=curl -f -L -k -o

    NOTE: Make sure to *not* add double quotes when setting the value
    of HTTP_CLIENT

    The suggested fix as you can see deals with getting around our inability to get GitHub’s security certificate.

    This is really not the right thing to do from a Security perspective. The real problem as I understand is that GitHub only supports TLS 1.2.

    In order for us to use PowerShell with TLS 1.2, I needed to do the following:

    1. In power shell, type in the following to find where your PowerShell profile lives:

      PS C:\> $profile
      C:\Users\{YourUserName}\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

    2. I went to that location but did not see a file. I ran this test to see if my PowerShell detected a profile file:

      PS C:\> test-path $profile
      False

      False means that the file is not there, but we already knew that right?

    3. Next, I created the PowerShell profile file like so:

      PS C:\> new-item -path $profile -itemtype file -forceDirectory: C:\Users\YourUserName\Documents\WindowsPowerShell

      Mode LastWriteTime Length Name
      ---- ------------- ------ ----
      -a---- 10/27/2018 2:38 PM 0 Microsoft.PowerShell_profile.ps1

    4. Once that command finished casting its spell, I did another test-path:

      PS C:\> test-path $profile
      True

      It sees my profile ps1 script now! Progress is Good.

    5. Next, using Notepad, I opened the Microsoft.PowerShell_profile.ps1 file. It was empty. I added the following line which allows PowerShell to use TLS 1.2 and saved the file:

      [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
    6. With renewed confidence, I tried to command lein to self-install once more:

      PS C:\> lein self-install
      Downloading Leiningen now...
      PS C:\>

      No news is good news. I thought. No error this time. What happened? Did it self-install this time?

    7. The only way to find out was to try running my repl once again, fingers crossed:

      PS C:\> lein repl
      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 org/sonatype/oss/oss-parent/7/oss-parent-7.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 60194 on host 127.0.0.1 - nrepl://127.0.0.1:60194
      REPL-y 0.3.7, nREPL 0.2.12
      Clojure 1.8.0
      Java HotSpot(TM) Client VM 1.8.0_191-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=>


      Success!!!!


    Now you know how to overcome this problem Take care and Happy coding.

    References:

    https://leiningen.org/

    StackOverflow

    Microsoft Tech Net