问题
How can I install OCaml with OPam on windows?
回答1:
I have been able to setup OCaml 4.03.0 in Windows 10, using the Opam package manager, by following the tutorial from this website: http://fdopen.github.io/opam-repository-mingw/. Here are the detailed steps that I did:
Install OCaml, Opam and Cygwin:
Download the installation package from this link: http://fdopen.github.io/opam-repository-mingw/installation/. There are both the 32 bit and 64 bit version, but I suggest to install the OCaml 64bit .
When running the graphical installation file, it will automatically install OCaml 4.02.3, Cygwin, Opam for you.
After installing, a shortcut for OCaml and Cygwin will be created on your Windows’ desktop.
Now, open the Cygwin terminal from the shortcut in your Windows’ desktop and do the followings:
Install some required libraries for Opam:
opam install depext
opam install depext-cygwinports
Upgrade your OCaml to 4.03.0 by using Opam:
opam switch 4.03.0+mingw64
eval `opam config env`
There you have OCaml 4.03.0 on Windows!
回答2:
I was able to run OCaml and Opam in Windows 10 using Windows Subsystem for Linux (WSL) without any problem.
Here's a very detail description and instruction OCaml on Windows: The easy way
Note: 2 typos in the article OCaml on Windows: The easy way as of this post, when you come across these two instructions please use the following
nano .ocamlinit
(*add an extra inano .ocamlint
*)open Core.Std;;
(*remove # from#open Core.Std;;
*)
Hope this helps someone!
**The initial link was removed, so here's the content
OCaml on Windows: The easy way
There have been a number of ways to run OCaml on Windows in the past, and there is an extensive list here. However, they all have downsides, whether that involves depending on someone else to update installer binaries, or having to deal with installing and managing Cygwin just to run OCaml.
Fortunately, with the release of Windows Subsystem for Linux (WSL), it’s possible to use the standard Ubuntu OCaml/OPAM easily from within windows, and integrate it with a windows GUI code editor. This guide assumes that you already have WSL set up - if not come back after setting it up by following this guide.
Given how fundamental modules such as Core by Jane Street are to doing any real work with OCaml we’re going to install the OPAM package manager and Core along with just the compiler. The end result is exactly the set up you need to begin the excellent Real World OCaml guide.
Firstly, we need to download and install ocaml and opam we need to add a personal package archive (ppa) to apt-get because the official Ubuntu repos have occasional issues. The code below adds this private repo to apt-get.
sudo add-apt-repository ppa:avsm/ppa
sudo apt-get update
Then just use apt-get to install ocaml, opam and m4 (a macro processor also required for the setup to work properly)
sudo apt-get install ocaml opam m4
The next step is to set up opam. Start with opam init, which will ask you to give it permission to update your .ocamlinit and .profile files. You can simply answer yes to both to put the changes through.
This lets you run the basic REPL loop with the ocaml command. However, a couple of extra bits and pieces are needed to get to the start of the Real World OCaml guide. We install these extras through opam with the command:
opam install core utop
Normally we’d now add the environmental variables to run the environment with the command:
eval 'opam config env'
Which should add the variables you need as explained here and here. However, when I tried it on WSL it didn’t work, I think as a side effect of the difference between the way windows and linux handles new lines. You can see this for yourself by running the command and then printenv to see all of the environmental variables - none of the variables have been set.
Instead if we use this command:
eval "$(opam config env)"
Then all of the commands are passed to ‘eval’ as a block, and so the whole thing evaluates cleanly, and if you run printenv you should see all of the required environmental variables.
The only thing that remains is to set up OCaml with the custom utop by editing the .ocamlinit file, which will be in your home directory.
Side Note: If you’re new to bash you might be confused that it doesn’t appear if you run ls in your home directory. This is because of the . in front of the filename which hides it by default. If you run ls -a
you will be able to see it.
Open this file with whatever your favourite text editor is, e.g. nano .ocamlinit
, and then add these lines. This is some OCaml code, which will execute on initialisation, i.e. every time you start up the OCaml environment.
#use "topfind";;
#thread;;
#camlp4o;;
#require "core.top";;
#require "core.syntax";;
open Core.Std;;
Everything is now doing what it’s supposed to do - if you run ocaml you will get utop with the Core module loaded and be ready to start working through the excellent Real World OCaml guide.
However, there is one last wrinkle. Setting environmental variables this way is temporary - if you exit WSL and then restart it with bash and then rerun printenv you will see that you have lost the environmental variables, and the ocaml command will now fail - unable to find the path for topfind because the environmental variables have gone.
To fix this we can add the command eval "$(opam config env)"
to the bottom of your .bashrc file in your home folder, which is run by bash every time you log in. This ensures that it runs automatically, so that you can just login and run ocaml to have a fully functional ocaml environment set up. If you switch compiler through the opam switch command, you will need to either re-run the command or restart the shell with exit and then bash to push the changes to the environment variables and update the version used by OCaml.
You’re now ready to start Real World OCaml - enjoy! This gives you the REPL loop under bash, which is good for learning. However, for more serious programs you need to write an .ml file - the next part (coming soon) covers building using the bash OCaml environment from a GUI code editor in windows, such as Visual Studio Code.
回答3:
Windows 10 CygWin64 standard C toolchain OCaml 4.02.3 + BuckleScript-1 ** WebAssembly spec/interpreter compiling from source OPam
install CygWin 64-bit setup-x86_64.exe
- choose your path (in the following abbreviated with cwd), everything else only default or next
- move the installer to cwd
install required packages for standard C toolchain from windows cmd prompt
cwd>setup-x86_64.exe -q -P wget -P gcc-g++ -P make -P diffutils -P libmpfr-devel -P libgmp-devel -P libmpc-devel
edit cwd/home\username\.bash_profile
, add
export SHELLOPTS
set -o igncr
start via Icon Cygwin64 Terminal
choose your path for installing the BuckleScript git (in the following abbreviated with bwd)
cd /cygdrive/bwd
git config --global core.eol lf
git config --global core.autocrlf false
git clone --recursive https://github.com/bloomberg/bucklescript
(cloning to /cygdrive/bwd/bucklescript
)
edit /cygdrive/bwd/bucklescript/.gittattribute
, add
* text=auto
choose your path for OCaml compiler to build (in the following abbreviated with owd)
configure and make
cd /cygdrive/owd/bucklescript/ocaml
./configure -prefix /owd
make world.opt
make install
install OPam
create switch (open issue, wait for answer)
compile bsc.exe (open issue, wait for answer)
install WebAssembly spec interpreter (WASM WAST switching)
issue WebAssembly/spec/interpreter/1052
... to be completed!
来源:https://stackoverflow.com/questions/39560241/how-can-i-install-ocaml-with-opam-on-windows