pages tagged configuration http://meng6net.localhost/tag/configuration/ <p><small>Copyright © 2005-2020 by <code>Meng Lu &lt;lumeng3@gmail.com&gt;</code></small></p> Meng Lu's home page ikiwiki Fri, 15 May 2020 01:57:52 +0000 Installing and configuring mutt http://meng6net.localhost/computing/installing_and_configuring/installing_and_configuring_mutt/ http://meng6net.localhost/computing/installing_and_configuring/installing_and_configuring_mutt/ computing configuration documentation homebrew installation macOS note pkgsrc software to-do Tue, 04 Feb 2020 19:44:45 +0000 2020-02-04T19:44:45Z <h2>Intro to Mutt</h2> <p><a href="http://www.mutt.org/"><code>mutt</code></a> is a text-based mail client for Unix operating systems.</p> <h2>Installing <code>mutt</code></h2> <pre><code>brew install mutt </code></pre> <h2>Installing <code>getmail</code></h2> <pre><code>brew install getmail </code></pre> Installing and configuring Homebrew http://meng6net.localhost/computing/installing_and_configuring/installing_and_configuring_Homebrew/ http://meng6net.localhost/computing/installing_and_configuring/installing_and_configuring_Homebrew/ Homebrew computing configuration installation macOS note software to-do Sun, 02 Jul 2017 02:09:51 +0000 2017-07-02T02:09:51Z <h2>Topics</h2> <h2>How to upgrade if Homebrew stuck at an old version?</h2> <pre> <code>$ "$(brew --repo)" &amp;&amp; git fetch &amp;&amp; git reset --hard origin/master &amp;&amp; brew update </code></pre> Installing and configuring Docker http://meng6net.localhost/computing/installing_and_configuring/installing_and_configuring_docker/ http://meng6net.localhost/computing/installing_and_configuring/installing_and_configuring_docker/ Docker computing configuration documentation draft installation note software Sun, 02 Jul 2017 01:09:02 +0000 2017-08-29T18:36:58Z <h2>macOS</h2> <h3>Homebrew</h3> <pre><code>brew cask install docker brew cask install docker-toolbox </code></pre> <h2>Create a virtual machine</h2> <pre><code>bash$ docker-machine create default </code></pre> <h2>Start the virtual machine</h2> <p>Start the virtual machine <code>default</code>:</p> <pre><code>bash$ docker-machine start bash$ docker-machine env export DOCKER_TLS_VERIFY="1" export DOCKER_HOST="tcp://192.168.99.100:2376" export DOCKER_CERT_PATH="/Users/meng/.docker/machine/machines/default" export DOCKER_MACHINE_NAME="default" # Run this command to configure your shell: # eval $(docker-machine env) bash$ eval "$(docker-machine env default)" </code></pre> <h2>Verify that the docker machine is working</h2> <pre><code>bash$ docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world b04784fba78d: Pull complete Digest: sha256:f3b3b28a45160805bb16542c9531888519430e9e6d6ffc09d72261b0d26ff74f Status: Downloaded newer image for hello-world:latest Hello from Docker! This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal. To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash Share images, automate workflows, and more with a free Docker ID: https://cloud.docker.com/ For more examples and ideas, visit: https://docs.docker.com/engine/userguide/ </code></pre> <h2>Run and test the 'tensorflow/tensorflow' Docker image</h2> <pre><code>bash$ docker run -it tensorflow/tensorflow:1.1.0 bash Unable to find image 'tensorflow/tensorflow:1.1.0' locally 1.1.0: Pulling from tensorflow/tensorflow c62795f78da9: Pull complete d4fceeeb758e: Pull complete 5c9125a401ae: Pull complete 0062f774e994: Pull complete 6b33fd031fac: Pull complete 353b34ef0a98: Pull complete 4f6aefc14b68: Pull complete ce066374c6ca: Pull complete c0755a91ab3a: Pull complete f03279b52d25: Pull complete d1c27c29b7e3: Pull complete 23807c5f4b3e: Pull complete Digest: sha256:27bd43f1cf71c45eb48cb6e067b7cef47b168ac11c685d55a3495d27f0d59543 Status: Downloaded newer image for tensorflow/tensorflow:1.1.0 root@d000fef7e8dc:/notebooks# root@d000fef7e8dc:/notebooks# python Python 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609] on linux2 Type "help", "copyright", "credits" or "license" for more information. &gt;&gt;&gt; &gt;&gt;&gt; import tensorflow as tf &gt;&gt;&gt; hello = tf.constant('Hello, TensorFlow!') &gt;&gt;&gt; sess = tf.Session() # It will print some warnings here. 2017-06-29 06:08:55.848559: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations. 2017-06-29 06:08:55.848626: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations. 2017-06-29 06:08:55.848663: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations. &gt;&gt;&gt; print(sess.run(hello)) Hello, TensorFlow! &gt;&gt;&gt; </code></pre> <h2>List all virtual machines</h2> <pre> <code>$ docker-machine ls NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS default - virtualbox Stopped Unknown </code></pre> <h2>Delete a virtual machine</h2> <pre><code>$ docker-machine rm default About to remove default WARNING: This action will delete both local reference and remote instance. Are you sure? (y/n): y Successfully removed default </code></pre> <h2>References</h2> <ul> <li> https://stackoverflow.com/questions/21871479/docker-cant-connect-to-docker-daemon</li> </ul> Installing and configuring TensorFlow http://meng6net.localhost/computing/installing_and_configuring/installing_and_configuring_TensorFlow/ http://meng6net.localhost/computing/installing_and_configuring/installing_and_configuring_TensorFlow/ Docker TensorFlow computing configuration documentation draft installation note software Sat, 01 Jul 2017 21:23:24 +0000 2017-07-01T21:23:24Z <h2>Install TensorFlow using 'tensorflow/tensorflow' Docker image</h2> <h3>Start the Docker virtual machine</h3> <p>Create a virtual machine if not already</p> <pre><code>bash$ docker-machine create default </code></pre> <p>Start the virtual machine <code>default</code>:</p> <pre><code>bash$ docker-machine start Starting "default"... (default) Check network to re-create if needed... (default) Waiting for an IP... Machine "default" was started. Waiting for SSH to be available... Detecting the provisioner... Started machines may have new IP addresses. You may need to re-run the `docker-machine env` command. &gt;&gt;&gt; elapsed time 35s bash$ docker-machine env export DOCKER_TLS_VERIFY="1" export DOCKER_HOST="tcp://192.168.99.100:2376" export DOCKER_CERT_PATH="/Users/meng/.docker/machine/machines/default" export DOCKER_MACHINE_NAME="default" # Run this command to configure your shell: # eval $(docker-machine env) bash$ eval "$(docker-machine env default)" </code></pre> <h3>Start 'tensorflow/tensorflow' Docker image</h3> <pre><code>$ export MY_WORKSPACE_DIR='/Users/meng/workspace' $ docker run -it \ --net=host \ --publish 6006:6006 \ --volume ${MY_WORKSPACE_DIR}/tensorflow_test:/tensorflow_test \ --workdir /tensorflow_test \ tensorflow/tensorflow:1.1.0 bash root@30d79c2e5fc3:/tensorflow_test# pwd /tensorflow_test </code></pre> <h3>Start TensorBoard</h3> <pre> <code>root@30d79c2e5fc3:/tensorflow_test# tensorboard --logdir training_summaries &amp; [1] 12 root@30d79c2e5fc3:/tensorflow_test# Starting TensorBoard 47 at http://0.0.0.0:6006 (Press CTRL+C to quit) root@30d79c2e5fc3:/tensorflow_test# </code></pre> <p>Open TensorBoard at</p> <pre><code>http://192.168.99.100:6006 </code></pre> <p>in a Web browser, where the IP is the same as <code>DOCKER_HOST</code> in the output of <code>docker-machine env</code>.</p> <h3>Download training data</h3> <pre> <code># curl -O http://download.tensorflow.org/example_images/flower_photos.tgz # tar xzf flower_photos.tgz # find flower_photos -type f | wc -l 3671 # cp -R flower_photos flower_photos_subset # rm flower_photos_subset/*/[2-9]* # find flower_photos_subset/ -type f | wc -l 1202 </code></pre> <h3>Download training script</h3> <pre> <code># curl -O https://raw.githubusercontent.com/tensorflow/tensorflow/r1.1/tensorflow/examples/image_retraining/retrain.py </code></pre> <h3>Training</h3> <pre><code># python retrain.py \ --bottleneck_dir=bottlenecks \ --how_many_training_steps=500 \ --model_dir=inception \ --summaries_dir=training_summaries/basic \ --output_graph=retrained_graph.pb \ --output_labels=retrained_labels.txt \ --image_dir=flower_photos_subset </code></pre> <h2>Python script to classify new images of flowers</h2> <p>Create a new file <code>label_image.py</code>:</p> <pre><code>import os, sys import tensorflow as tf os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' # change this as you see fit image_path = sys.argv[1] # Read in the image_data image_data = tf.gfile.FastGFile(image_path, 'rb').read() # Loads label file, strips off carriage return label_lines = [line.rstrip() for line in tf.gfile.GFile("retrained_labels.txt")] # Unpersists graph from file with tf.gfile.FastGFile("retrained_graph.pb", 'rb') as f: graph_def = tf.GraphDef() graph_def.ParseFromString(f.read()) tf.import_graph_def(graph_def, name='') with tf.Session() as sess: # Feed the image_data as input to the graph and get first prediction softmax_tensor = sess.graph.get_tensor_by_name('final_result:0') predictions = sess.run(softmax_tensor, \ {'DecodeJpeg/contents:0': image_data}) # Sort to show labels of first prediction in order of confidence top_k = predictions[0].argsort()[-len(predictions[0]):][::-1] for node_id in top_k: human_string = label_lines[node_id] score = predictions[0][node_id] print('%s (score = %.5f)' % (human_string, score)) </code></pre> <p>Classify a new image:</p> <pre> <code># python label_image.py flower_photos/daisy/99306615_739eb94b9e_m.jpg daisy (score = 0.47996) dandelion (score = 0.24667) sunflowers (score = 0.24508) tulips (score = 0.02018) roses (score = 0.00811) </code></pre> <h3>Exit the Docker image and stop the Docker virtual machine</h3> <p>Ctrl+D to exit Docker image and then run</p> <pre><code>$ docker-machine stop </code></pre> <h2>References</h2> <ul> <li> https://codelabs.developers.google.com/codelabs/tensorflow-for-poets</li> </ul> Fix Adobe Connect for Google Chrome 42 http://meng6net.localhost/computing/misc/fix_Adobe_Connect_for_Google_Chrome_42/ http://meng6net.localhost/computing/misc/fix_Adobe_Connect_for_Google_Chrome_42/ configuration note software Tue, 16 May 2017 23:59:39 +0000 2017-05-16T23:59:39Z <p>Adobe Connect, which is the teleconference software I use for work, stopped working in Google Chrome <code>42.0.\&lt;some version\&gt;</code>. After ignoring it for a while and several failed attempts to fix it, I finally figured out how to resurrect it.</p> <ol> <li>Open <code>chrome://flags/</code> in Chrome, enable the plug-in under 'Enable NPAPI Mac, Windows';</li> <li>Install Adobe NPAPI Flash plug-in: http://get.adobe.com/flashplayer;</li> <li>Open <code>chrome://plugins</code> in Chrome, under the section 'Adobe Flash Player', disable PPAPI and enable NPAPI.</li> </ol> <h2>References</h2> <ul> <li><a href= "https://helpx.adobe.com/adobe-connect/kb/google-chrome-browser-incompatibility.html"> Adobe Connect Help &gt; Chrome browser incompatibility with Connect Add-in</a></li> <li><a href= "https://code.google.com/p/chromium/issues/detail?id=453263">Chroium project Issue 453263: Missing NPAPI plugins</a></li> </ul> Installing and configuring Apache HTTP Server on macOS http://meng6net.localhost/computing/installing_and_configuring/installing_and_configuring_Apache_HTTP_Server_on_macOS/ http://meng6net.localhost/computing/installing_and_configuring/installing_and_configuring_Apache_HTTP_Server_on_macOS/ Apache HTTP Server computing configuration documentation installation macOS note software Tue, 16 May 2017 23:59:39 +0000 2018-10-13T03:33:59Z <h2>previous version of Apache configuration files</h2> <h2>Apache configuration file</h2> <pre><code>$ cd /etc/apache2/users $ touch "${USERNAME}.conf" $ sudo chmod 644 "${USERNAME}.conf" </code></pre> <p>The configuration file <code>"${USERNAME}.conf"</code>:</p> <pre><code>&lt;Directory "/Users/XXX/Sites/"&gt; AllowOverride All Options Indexes MultiViews FollowSymLinks Require all granted &lt;/Directory&gt; </code></pre> <h2><code>/etc/apache2/httpd.conf</code></h2> <pre> <code>LoadModule authz_host_module libexec/apache2/mod_authz_host.so LoadModule authz_core_module libexec/apache2/mod_authz_core.so LoadModule userdir_module libexec/apache2/mod_userdir.so LoadModule vhost_alias_module libexec/apache2/mod_vhost_alias.so Include /private/etc/apache2/extra/httpd-userdir.conf Include /private/etc/apache2/extra/httpd-vhosts.conf </code></pre> <h2><code>/etc/apache2/extra/httpd-userdir.conf</code></h2> <pre><code>Include /private/etc/apache2/users/*.conf </code></pre> <h2>Restarting Apache server</h2> <pre><code>$ sudo apachectl restart </code></pre> <h2>References</h2> <ul> <li> <p>John Foderaro, <a href= "https://medium.com/@JohnFoderaro/how-to-set-up-apache-in-macos-sierra-10-12-bca5a5dfffba"> How to Set up Apache in macOS Sierra 10.12</a>, 2016.</p> </li> <li> <p><a href= "https://serverfault.com/questions/520195/how-does-servername-and-serveralias-work"> How does ServerName and ServerAlias work?</a></p> </li> <li> <p><a href= "https://wiki.apache.org/httpd/CommonMisconfigurations">Common Apache Misconfigurations</a></p> </li> </ul> Installing and configuring Apache2 http://meng6net.localhost/computing/installing_and_configuring/installing_and_configuring_Apache2/ http://meng6net.localhost/computing/installing_and_configuring/installing_and_configuring_Apache2/ apache apache2 computing configuration documentation installation note software Tue, 16 May 2017 23:59:39 +0000 2017-05-16T23:59:39Z <h3>Uninstalling Apache server</h3> <p>If Apache server has been installed, you may want to remove it and re-install it.</p> <p>Update packages:</p> <pre><code>sudo apt-get update sudo apt-get autoremove </code></pre> <p>Uninstall Apache2 and its configuration files:</p> <pre><code>sudo apt-get purge apache2 sudo apt-get autoremove </code></pre> <h3>Installing</h3> <p>Reinstall Apache2 and PHP5 packages:</p> <pre><code>sudo apt-get install apache2 php5 </code></pre> <h3>Setting up <code>~/public_html/</code></h3> <p>Create <code>public_html</code> directory for storing Web site files:</p> <pre><code>mkdir $HOME/public_html </code></pre> <p>Configure Apache2 server to use <code>$HOME/public_html</code> as the Web site root path:</p> <pre><code>cd /etc/apache2/mods-enabled sudo ln -s ../mods-available/userdir.conf userdir.conf sudo ln -s ../mods-available/userdir.load userdir.load </code></pre> <h3>Restarting Apache2 server</h3> <pre><code>sudo /etc/init.d/apache2 restart </code></pre> <p>Or</p> <pre><code>sudo service apache2 restart </code></pre> <h3>Installing PHP</h3> <pre> <code>sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt </code></pre> <h3>Installing MySQL</h3> <p>See "<a href="http://meng6net.localhost/tag/configuration/installing_and_configuring_mysql.html">Installing and configuring MySQL</a>."</p> <h2>References</h2> <ul> <li><a href= "https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-14-04"> How To Install Linux, Apache, MySQL, PHP (LAMP) stack on Ubuntu 14.04</a></li> </ul> Installing and configuring Haskell http://meng6net.localhost/computing/installing_and_configuring/installing_and_configuring_Haskell/ http://meng6net.localhost/computing/installing_and_configuring/installing_and_configuring_Haskell/ Haskell computing configuration documentation installation note software Tue, 16 May 2017 23:59:39 +0000 2017-05-20T22:12:25Z <h2><code>cabal</code> VS. <code>stack</code></h2> <p><code>cabal</code> and <code>stack</code> are two tools one can use to install Glasgow Haskell Compiler (GHC), i.e. the binaries <code>ghc</code> and <code>ghci</code>, and Haskell software packages. <code>stack</code> installs Haskell programs in <code>~/.stack</code> and <code>cabal</code> installs in <code>~/.cabal</code>. Using both <code>cabal</code> and <code>stack</code>, or either one of them is possible, but it seems the current general wisdom is that <code>stack</code> is more user friendly especially for beginners. So I chose to uninstall <code>cabal</code> and delete <code>~/.cabal</code>, and use <code>stack</code> only.</p> <h2>Install Haskell compiler and softwares using <code>stack</code></h2> <p><code>stack</code> is built on top of <code>cabal</code> (which in turn relies on <code>ghc-pkg</code>), the package management system for Haskell softwares, but is more user friendly in some ways.</p> <ul> <li> <p>Uninstall the ghc installed using the system's package management system</p> <ul> <li> <p>macOS:</p> <pre><code> brew uninstall --force cabal-install brew uninstall --force ghc </code></pre></li> <li> <p>Linux:</p> <pre><code> sudo apt-get remove ghc sudo apt-get remove cabal-install </code></pre></li> </ul> </li> <li> <p>Install <code>stack</code></p> <ul> <li> <p>macOS:</p> <pre><code> brew install haskell-stack </code></pre></li> <li> <p>Linux: Follow the instruction about installation in the official <a href= "http://docs.haskellstack.org/en/stable/install_and_upgrade/#ubuntu"> documentation</a>. Don't just do <code>sudo apt-get install haskell-stack</code>.</p> </li> </ul> </li> <li> <p>Install <code>ghc</code></p> <pre><code> stack setup </code></pre></li> <li> <p>If you want to use binaries installed via <code>stack</code> regularly, put them on path. Run <code>stack path</code> and append the paths of form <code>~/.stack/.../bin</code> in the output to <code>$PATH</code> in <code>~/.bashrc</code>.</p> </li> <li> <p>Install packages using <code>stack</code>:</p> <pre><code> stack install ghc-mod stack install cabal-install stack install hlint stack install pandoc stack install purescript stack install wreq stack install lens stack install ihaskell stack install projectile stack install use-package stack install which-key stack install apply-refact stack install codex stack install hasktags </code></pre> <ul> <li><code>ihaskell</code>: <a href= "https://github.com/gibiansky/IHaskell">IHaskell</a>, Haskell kernel for Jupyter notebooks.</li> </ul> </li> </ul> <h2>Install Haskell compiler and softwares using <code>cabal</code></h2> <ul> <li> <p>Install <code>ghc</code> and <code>cabal</code></p> <pre><code> brew install cabal-install ghc </code></pre></li> <li> <p>Install packages via <code>cabal</code></p> <pre><code> cabal update cabal install happy # 2016-3-5: prerequisite for ghc-mod cabal install ghc-mod hlint haskell-docs </code></pre></li> </ul> <h2>Verifying the stack and Haskell installation</h2> <pre><code>cd $HOME # Assume 'stack setup' has been run. stack init stack build --dependencies-only --test </code></pre> <h2>Configure Emacs for Haskell development</h2> <p>Install the following Emacs packages, ideally using the <a href= "https://elpa.gnu.org/">GNU Emacs Lisp Package Archive</a> (see also <a href="https://www.emacswiki.org/emacs/ELPA">EmacsWiki: ELPA</a>):</p> <ul> <li>Emacs packages specifically relevant for Haskell: <ul> <li>haskell-mode</li> <li>haskell-snippets</li> <li>flycheck-hlint</li> <li>intero</li> </ul> </li> <li><a href= "http://meng6net.localhost/computing/installing_and_configuring/installing_and_configuring_emacs"> Other Emacs packages</a> generally helpful.</li> </ul> <h2>Configure a Haskell project using <code>stack</code></h2> <h3>Create a project</h3> <pre><code>cd path/to/workspace/ stack new haskell-stack-test-project cd haskell-stack-test-project stack setup stack build --dependencies-only --test </code></pre> <p>This creates a new project using template <code>~/.stack/templates/new-template.hsfiles</code>. The project directory structure:</p> <pre><code>$ tree . ├── LICENSE ├── Setup.hs ├── app │ └── Main.hs ├── haskell-stack-test-project.cabal ├── src │ └── Lib.hs ├── stack.yaml └── test └── Spec.hs </code></pre> <p>Remarks:</p> <ul> <li><code>app/</code> contains the source file(s) for more application-specific logic, including a <code>app/Main.hs</code>.</li> <li><code>src/</code> contains the source file(s) for more shareable and general-purpose code.</li> </ul> <h3>Build</h3> <pre><code>$ cd path/to/haskell-stack-test-project $ stack build haskell-stack-test-project-0.1.0.0: configure Configuring haskell-stack-test-project-0.1.0.0... haskell-stack-test-project-0.1.0.0: build Preprocessing library haskell-stack-test-project-0.1.0.0... [1 of 1] Compiling Lib ( src/Lib.hs, .stack-work/dist/x86_64-osx/Cabal-1.22.5.0/build/Lib.o ) In-place registering haskell-stack-test-project-0.1.0.0... Preprocessing executable 'haskell-stack-test-project-exe' for haskell-stack-test-project-0.1.0.0... [1 of 1] Compiling Main ( app/Main.hs, .stack-work/dist/x86_64-osx/Cabal-1.22.5.0/build/haskell-stack-test-project-exe/haskell-stack-test-project-exe-tmp/Main.o ) Linking .stack-work/dist/x86_64-osx/Cabal-1.22.5.0/build/haskell-stack-test-project-exe/haskell-stack-test-project-exe ... haskell-stack-test-project-0.1.0.0: copy/register Installing library in /Users/meng/Dropbox/WorkSpace-Dropbox/Computing/repo-meng-lib/Haskell/haskell-stack-test-project/.stack-work/install/x86_64-osx/lts-5.5/7.10.3/lib/x86_64-osx-ghc-7.10.3/haskell-stack-test-project-0.1.0.0-BCjrGi4SAkj4MdkT4tD42y Installing executable(s) in /Users/meng/Dropbox/WorkSpace-Dropbox/Computing/repo-meng-lib/Haskell/haskell-stack-test-project/.stack-work/install/x86_64-osx/lts-5.5/7.10.3/bin Registering haskell-stack-test-project-0.1.0.0... </code></pre> <p>The path to the built executable is contained in the line starting with <code>Linking</code>: <code>Linking .stack-work/dist/x86_64-osx/Cabal-1.22.5.0/build/haskell-stack-test-project-exe/haskell-stack-test-project-exe ...</code>.</p> <pre> <code>$ .stack-work/dist/x86_64-osx/Cabal-1.22.5.0/build/haskell-stack-test-project-exe/haskell-stack-test-project-exe someFunc </code></pre> <h2>Configure a Haskell project using IntelliJ IDEA</h2> <ul> <li> <p>Install JetBrains' Haskell plug-in.</p> </li> <li> <p>Configure Languages &amp; Frameworks | Haskell:</p> </li> </ul> <p><a href= "http://meng6net.localhost/images/computing/installing_and_configuring/installing_and_configuring_Haskell/configure_Haskell_stack.png"> <img src= "http://meng6net.localhost/computing/installing_and_configuring/installing_and_configuring_Haskell/957x-configure_Haskell_stack.png" width="957" height="203" class="img" /></a></p> <p>If using binaries installed via <code>cabal</code>:</p> <p><a href= "http://meng6net.localhost/images/computing/installing_and_configuring/installing_and_configuring_Haskell/configure_Haskell_cabal.png"> <img src= "http://meng6net.localhost/computing/installing_and_configuring/installing_and_configuring_Haskell/763x-configure_Haskell_cabal.png" width="763" height="199" class="img" /></a></p> <ul> <li>Create a Haskell project and its first component.</li> </ul> <p>Use menu File | New | Project and select 'Haskell', click 'next', and choose name for the project and the name for the first module and its sub-directory:</p> <p><a href= "http://meng6net.localhost/images/computing/installing_and_configuring/installing_and_configuring_Haskell/create_Haskell_project_in_IntelliJ_IDEA.png"> <img src= "http://meng6net.localhost/computing/installing_and_configuring/installing_and_configuring_Haskell/945x-create_Haskell_project_in_IntelliJ_IDEA.png" width="945" height="640" class="img" /></a></p> <ul> <li>Set GHC (<code>ghc</code>) as the platform SDK: use menu File | Project Structure, and select '+' and navigate to the installation path of the desired version of <code>ghc</code>, e.g. <code>/Users/meng/.stack/programs/x86_64-osx/ghc-7.10.3</code> which is installed via <code>stack</code> or <code>/usr/local/Cellar/ghc/7.10.3</code>, which is installed via <code>brew</code>.</li> </ul> <p><a href= "http://meng6net.localhost/images/computing/installing_and_configuring/installing_and_configuring_Haskell/set_GHC_as_platform_SDK.png"> <img src= "http://meng6net.localhost/computing/installing_and_configuring/installing_and_configuring_Haskell/786x-set_GHC_as_platform_SDK.png" width="786" height="283" class="img" /></a></p> <ul> <li>Optionally, create additional modules in the project: use menu File | New | Module, select 'Haskell', and choose name for the module and directory.</li> </ul> <p><a href= "http://meng6net.localhost/images/computing/installing_and_configuring/installing_and_configuring_Haskell/Haskell_project_with_two_modules_in_IntelliJ_IDEA.png"> <img src= "http://meng6net.localhost/computing/installing_and_configuring/installing_and_configuring_Haskell/621x-Haskell_project_with_two_modules_in_IntelliJ_IDEA.png" width="621" height="415" class="img" /></a></p> <h2>References</h2> <ul> <li> <p>A 2-hour long video tutorial on setting up Haskell environment using <code>stack</code> by Christopher Allen and Julie Moronuki: <a href= "https://www.youtube.com/watch?v=sRonIB8ZStw">https://www.youtube.com/watch?v=sRonIB8ZStw</a>.</p> </li> <li> <p><a href= "https://www.stackage.org/">https://www.stackage.org/</a></p> </li> <li> <p>The Haskell Tool Stack documentation, <a href= "http://docs.haskellstack.org/en/stable/README/">http://docs.haskellstack.org/en/stable/README/</a></p> <ul> <li>guide: <a href= "http://docs.haskellstack.org/en/stable/GUIDE/">http://docs.haskellstack.org/en/stable/GUIDE/</a></li> </ul> </li> </ul> Installing and configuring Java on macOS http://meng6net.localhost/computing/installing_and_configuring/installing_and_configuring_Java_on_macOS/ http://meng6net.localhost/computing/installing_and_configuring/installing_and_configuring_Java_on_macOS/ Java computing configuration documentation installation java macOS mac os x note software tutorial Tue, 16 May 2017 23:59:39 +0000 2017-05-16T23:59:39Z <p>This is a note on my experience of installing Java on macOS 10.9.2.</p> <p>macOS has its own system Java which as of macOS 10.9.2 is at version 1.6.0_65. It's more or less consistent with Java 6 (<a href="http://docs.oracle.com/javase/specs/">Java Language and Virtual Machine Specifications</a> version <a href= "http://docs.oracle.com/javase/specs/">SE 6</a>). I'd like to keep macOS's system Java for various tasks and applications such as Mathematica which requires on Java 6. It's said that Apple no longer supports Java as a system component, so it's possile there will not be future major version update to Java 7 and higher.</p> <p>The new "Java" I'd like to install is Oracle's Java. Oracle calls it "Java Platform (JDK) Platform". JDK is Java Development Kit which is the software package one needs to do Java software development. It's currently at version "Java SE 7" and is updated to "JDK SE 8" in March 2014. I'd like to install it for learning new Java features and used it in some projects.</p> <h2>macOS's system Java</h2> <h3>The 'java' executable and Java Virtual Machines</h3> <p>The default command-line <code>java</code> on macOS 10.9.2 is version <code>1.6.0_65</code>:</p> <pre><code>$ which java /usr/bin/java $ java -version java version "1.6.0_65" Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609) Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode) </code></pre> <p>This <code>java</code> along with other Java related binaries in the same path <code>/usr/bin/</code> are actually symbolic links pointing to OS X's default installation directory for Java which in turn is part of system libraries <code>/System/Library/</code>:</p> <pre><code>$ ls -l /usr/bin/*java* lrwxr-xr-x 1 root wheel 74 Nov 3 10:29 /usr/bin/java -&gt; /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java lrwxr-xr-x 1 root wheel 75 Nov 3 10:29 /usr/bin/javac -&gt; /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/javac lrwxr-xr-x 1 root wheel 77 Nov 3 10:29 /usr/bin/javadoc -&gt; /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/javadoc lrwxr-xr-x 1 root wheel 75 Nov 3 10:29 /usr/bin/javah -&gt; /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/javah lrwxr-xr-x 1 root wheel 75 Nov 3 10:29 /usr/bin/javap -&gt; /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/javap lrwxr-xr-x 1 root wheel 76 Nov 3 10:29 /usr/bin/javaws -&gt; /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/javaws </code></pre> <p>So the <code>java</code> at command line is actually using <code>/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java</code>. The <code>Current</code> directory is actually also a symbolic link:</p> <pre> <code>$ ls -la /System/Library/Frameworks/JavaVM.framework/Versions/ total 64 drwxr-xr-x 11 root wheel 374 Nov 3 10:30 . drwxr-xr-x 12 root wheel 408 Nov 3 10:30 .. lrwxr-xr-x 1 root wheel 10 Nov 3 10:29 1.4 -&gt; CurrentJDK lrwxr-xr-x 1 root wheel 10 Nov 3 10:29 1.4.2 -&gt; CurrentJDK lrwxr-xr-x 1 root wheel 10 Nov 3 10:29 1.5 -&gt; CurrentJDK lrwxr-xr-x 1 root wheel 10 Nov 3 10:29 1.5.0 -&gt; CurrentJDK lrwxr-xr-x 1 root wheel 10 Nov 3 10:29 1.6 -&gt; CurrentJDK lrwxr-xr-x 1 root wheel 10 Nov 3 10:29 1.6.0 -&gt; CurrentJDK drwxr-xr-x 8 root wheel 272 Nov 3 10:30 A lrwxr-xr-x 1 root wheel 1 Nov 3 10:29 Current -&gt; A lrwxr-xr-x 1 root wheel 59 Nov 3 10:29 CurrentJDK -&gt; /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents </code></pre> <p>So this further mean the <code>java</code> at command line is actually using <code>/System/Library/Frameworks/JavaVM.framework/Versions/A/Commands/java</code>:</p> <pre> <code>$ ls -la /System/Library/Frameworks/JavaVM.framework/Versions/A/Commands/java -rwxr-xr-x 1 root wheel 54624 Nov 3 10:29 /System/Library/Frameworks/JavaVM.framework/Versions/A/Commands/java $ /System/Library/Frameworks/JavaVM.framework/Versions/A/Commands/java -version java version "1.6.0_65" Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609) Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode) </code></pre> <p>Difference between <code>/System/Library/Frameworks/</code> and <code>/Library/</code>:</p> <p>The <code>/System/Library/Frameworks/</code> path is where macOS installs its essential framework packages such as Java. The framework packages are shared by multiple applications. Different applications may need different versions of the same package so in general there can be multiple versions of the same package. Third-party libraries is installed in <code>/Library/</code>.</p> <p><code>/System/Library/Java/</code>:</p> <p>All the previous versions of Java {<code>1.4</code>, <code>1.5</code>, ..., <code>1.6.0</code>} is redirected to <code>CurrentJDK</code> and then to <code>/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents</code>, perhaps for backwards compatibility. And the "current" Java is pointed to <code>Current/</code> and then to <code>A/</code>. I guess 'A' stands for "Automatic". Also, I noted that there is one Apple's Java VM:</p> <pre><code>$ ls -la /System/Library/Java/JavaVirtualMachines/ total 0 drwxr-xr-x 3 root wheel 102 Oct 10 11:13 . drwxr-xr-x 5 root wheel 170 Nov 3 10:30 .. drwxr-xr-x 3 root wheel 102 Oct 10 11:13 1.6.0.jdk </code></pre> <p>I'm not sure what's the relation between <code>/System/Library/Frameworks/JavaVM.framework/</code> and <code>/System/Library/Java</code>. My guess is that <code>JavaVM.framework</code> is newly introduced and used 1) as an "interface" which maintain various links to <code>/System/Library/Java/</code> for previous versions; 2) to store the "current" version of system "Java" in <code>/System/Library/Frameworks/JavaVM.framework/Versions/A/</code>.</p> <p>Apple has a web site that provides <a href= "http://support.apple.com/downloads/#java">downloading of macOS system Java</a>.</p> <h3><code>JAVA_HOME</code> environment variable</h3> <pre><code>$ echo $JAVA_HOME /System/Library/Frameworks/JavaVM.framework/Home $ ls -la /System/Library/Frameworks/JavaVM.framework/Home lrwxr-xr-x 1 root wheel 24 Apr 1 19:36 /System/Library/Frameworks/JavaVM.framework/Home -&gt; Versions/CurrentJDK/Home $ ls -la /System/Library/Frameworks/JavaVM.framework/Versions/ total 64 drwxr-xr-x 11 root wheel 374 Apr 1 19:37 . drwxr-xr-x 12 root wheel 408 Apr 1 19:37 .. lrwxr-xr-x 1 root wheel 10 Apr 1 19:36 1.4 -&gt; CurrentJDK lrwxr-xr-x 1 root wheel 10 Apr 1 19:36 1.4.2 -&gt; CurrentJDK lrwxr-xr-x 1 root wheel 10 Apr 1 19:36 1.5 -&gt; CurrentJDK lrwxr-xr-x 1 root wheel 10 Apr 1 19:36 1.5.0 -&gt; CurrentJDK lrwxr-xr-x 1 root wheel 10 Apr 1 19:36 1.6 -&gt; CurrentJDK lrwxr-xr-x 1 root wheel 10 Apr 1 19:36 1.6.0 -&gt; CurrentJDK drwxr-xr-x 8 root wheel 272 Apr 1 19:37 A lrwxr-xr-x 1 root wheel 1 Apr 1 19:36 Current -&gt; A lrwxr-xr-x 1 root wheel 59 Apr 1 19:36 CurrentJDK -&gt; /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents </code></pre> <p>Notice that it does not point to a <code>Home</code> inside <code>/System/Library/Frameworks/JavaVM.framework/Versions/A/</code>. Actually <code>A/</code> does not contain a <code>Home/</code>. I'm not sure why there are both <code>/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Commands</code> (which points to <code>/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin/</code>) and <code>/System/Library/Frameworks/JavaVM.framework/Versions/A/Commands</code>.</p> <h3>(Re-)install macOS's system Java</h3> <p>If for some reason you need to (re-)install Apple's system Java, you can download it from Apple's support site <a href= "http://support.apple.com/downloads/#java">http://support.apple.com/downloads/#java</a>. For example, as of April 2014, I will choose "Java for OS X 2013-005" for macOS 10.9.2.</p> <p>There is also packages called <a href= "https://developer.apple.com/downloads/index.action?name=Java%20Developer"> "Java for macOS 10.6 Update 17 Developer Package" or "Java for OS X 2013-005 Developer Package"</a> that "contains JavaDoc, tools documentation, and native framework headers". I've never tried these.</p> <h3>Preventing future macOS update to Java</h3> <p>If you decide to use Oracle JDK exclusively in future, it maybe desirable to more "thoroughly" delete Apple's Java. This is what I've not attempted to do.</p> <p>The possible removals you'd need are</p> <pre><code>$ rm -rf /System/Library/Java/JavaVirtualMachines/ $ rm /private/var/db/receipts/com.apple.pkg.JavaForMacOSX* </code></pre> <p>and edit the installation receipts <code>/Library/Receipts/InstallHistory.plist</code> and remove the <code>&lt;dict&gt;</code> XML elements that has <code>com.apple.Java*</code> in it:</p> <pre> <code>$ ack "com\.apple.*ava.*" /Library/Receipts/InstallHistory.plist &lt;string&gt;com.apple.pkg.JavaSDKLeo&lt;/string&gt; &lt;string&gt;com.apple.pkg.JavaForMacOSX10.6Update3&lt;/string&gt; &lt;string&gt;com.apple.pkg.JavaForMacOSX10.6Update4&lt;/string&gt; &lt;string&gt;com.apple.pkg.JavaForMacOSX10.6Update5&lt;/string&gt; &lt;string&gt;com.apple.pkg.JavaForMacOSX10.6&lt;/string&gt; &lt;string&gt;com.apple.pkg.JavaForMacOSX10.6&lt;/string&gt; &lt;string&gt;com.apple.pkg.JavaSecurity&lt;/string&gt; &lt;string&gt;com.apple.pkg.JavaForMacOSX10.6&lt;/string&gt; &lt;string&gt;com.apple.pkg.JavaSecurity&lt;/string&gt; &lt;string&gt;com.apple.pkg.JavaForMacOSX10.6&lt;/string&gt; &lt;string&gt;com.apple.pkg.JavaSecurity&lt;/string&gt; &lt;string&gt;com.apple.pkg.JavaForMacOSX10.6&lt;/string&gt; &lt;string&gt;com.apple.pkg.JavaSecurity&lt;/string&gt; &lt;string&gt;com.apple.pkg.JavaForMacOSX10.6&lt;/string&gt; &lt;string&gt;com.apple.pkg.JavaSecurity&lt;/string&gt; &lt;string&gt;com.apple.pkg.JavaForMacOSX10.6&lt;/string&gt; &lt;string&gt;com.apple.pkg.JavaSecurity&lt;/string&gt; &lt;string&gt;com.apple.pkg.JavaForMacOSX10.6&lt;/string&gt; &lt;string&gt;com.apple.pkg.JavaSecurity&lt;/string&gt; &lt;string&gt;com.apple.pkg.JavaTools&lt;/string&gt; &lt;string&gt;com.apple.pkg.JavaEssentials&lt;/string&gt; &lt;string&gt;com.apple.pkg.JavaEssentials&lt;/string&gt; &lt;string&gt;com.apple.pkg.JavaForMacOSX107&lt;/string&gt; &lt;string&gt;com.apple.pkg.JavaSecurity&lt;/string&gt; &lt;string&gt;com.apple.pkg.JavaMDNS&lt;/string&gt; &lt;string&gt;com.apple.pkg.JavaEssentials&lt;/string&gt; &lt;string&gt;com.apple.pkg.JavaForMacOSX107&lt;/string&gt; &lt;string&gt;com.apple.pkg.JavaSecurity&lt;/string&gt; &lt;string&gt;com.apple.pkg.JavaMDNS&lt;/string&gt; &lt;string&gt;com.apple.pkg.JavaTools&lt;/string&gt; &lt;string&gt;com.apple.pkg.JavaEssentials&lt;/string&gt; &lt;string&gt;com.apple.pkg.JavaEssentials&lt;/string&gt; &lt;string&gt;com.apple.pkg.JavaForMacOSX107&lt;/string&gt; &lt;string&gt;com.apple.pkg.JavaSecurity&lt;/string&gt; &lt;string&gt;com.apple.pkg.JavaMDNS&lt;/string&gt; </code></pre> <h2>Installing Oracle's Java</h2> <h3>The path <code>/Library/Java/</code></h3> <p>Third-party Java will be installed to <code>/Library/Java</code>. Note there is not a <code>/System/</code> in front of it.</p> <pre><code>$ ls -la /Library/Java total 8 drwxrwxr-x 5 root admin 170 Nov 3 10:30 . drwxr-xr-x+ 72 root wheel 2448 Mar 8 08:08 .. drwxrwxr-x 2 root admin 68 Nov 3 10:30 Extensions lrwxr-xr-x 1 root wheel 48 Nov 3 10:29 Home -&gt; /System/Library/Frameworks/JavaVM.framework/Home drwxr-xr-x 2 root wheel 68 Nov 3 10:30 JavaVirtualMachines $ ls -la /Library/Java/JavaVirtualMachines/ total 0 drwxr-xr-x 2 root wheel 68 Nov 3 10:30 . drwxrwxr-x 5 root admin 170 Nov 3 10:30 .. </code></pre> <p>The symbolic link <code>Home -&gt; /System/Library/Frameworks/JavaVM.framework/Home</code> is how macOS by default manages the <code>$JAVA_HOME</code> environment variable for third-party Java. <code>$JAVA_HOME</code> by default is set to <code>/Library/Java/Home</code> which is updated to point to the current version of Java <code>/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/</code>.</p> <p>Currently I have no third-party Java and hence an empty <code>/Library/Java/JavaVirtualMachines/</code>.</p> <p>To install a new non-system non-Apple Java on Mac, one can install <a href= "http://www.oracle.com/technetwork/java/javase/downloads/index.html"> Oracle's JDK</a>, and possibly <a href= "http://openjdk.java.net/projects/macosx-port/">OpenJDK</a>). These have versions newer than Apple's Java.</p> <p>My goal at the time of writing this note is to install the newer Java (Java Language and Virtual Specification, version SE 7 or even version "Java SE 8") while keep macOS's own system Java (version "Java SE 6"), since I need both for different work.</p> <h3>Installing Oracle's JDK</h3> <p>To install "Java 7", download "Java SE Development Kit 7" for "macOS x64" from <a href= "http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html"> Oracle</a>. Install that. After that, you should find <code>/Library/Java/JavaVirtualMachines/</code> has the newly installed Oracle JDK:</p> <pre><code>$ ls /Library/Java/JavaVirtualMachines jdk1.7.0_51.jdk $ /Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/bin/java -version java version "1.7.0_51" Java(TM) SE Runtime Environment (build 1.7.0_51-b13) Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode) </code></pre> <p>But this does not affect the default command-line <code>java</code>:</p> <pre><code>$ java -version java 1.6.0_65 </code></pre> <p>Now you have both Java 6 and 7 on the computer and can use them for different purposes.</p> <h3>Making Oracle Java binaries available at command line</h3> <p>Depending on if it's desirable to you, you may want to link Java related binaries in <code>/usr/bin</code></p> <pre><code>$ ls -la /usr/bin/*java* lrwxr-xr-x 1 root wheel 74 Nov 3 10:29 /usr/bin/java -&gt; /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java lrwxr-xr-x 1 root wheel 75 Nov 3 10:29 /usr/bin/javac -&gt; /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/javac lrwxr-xr-x 1 root wheel 77 Nov 3 10:29 /usr/bin/javadoc -&gt; /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/javadoc lrwxr-xr-x 1 root wheel 75 Nov 3 10:29 /usr/bin/javah -&gt; /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/javah lrwxr-xr-x 1 root wheel 75 Nov 3 10:29 /usr/bin/javap -&gt; /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/javap lrwxr-xr-x 1 root wheel 76 Nov 3 10:29 /usr/bin/javaws -&gt; /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/javaws </code></pre> <p>to Oracle's Java, either under a different name, say <code>java7</code>, or the default name <code>java</code>, and optionally rename the existing macOS's <code>java</code> to <code>java6</code> first. I created <code>java7</code>:</p> <pre> <code>$ sudo ln -s /Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/bin/java /usr/bin/java7 $ sudo ln -s /Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/bin/javac /usr/bin/javac7 ... </code></pre> <p>And you probably want to keep <code>$JAVA_HOME</code> consistent with <code>java</code>. If <code>java</code> is pointing to Oracle Java, you'd want</p> <pre> <code>$ ln -s /Library/Java/Home /Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home </code></pre> <h2>Managing <code>JAVA_HOME</code> for different environments</h2> <p><code>JAVA_HOME</code> is a UNIX envrionment variable that are sometimes used to determine which and how Java Virtual Machine is run. It's a somewhat complex issue to set them appropriately for different purposes.</p> <p>Here is what I've done:</p> <h3>Setting <code>JAVA_HOME</code> for Bash</h3> <p>Add the following code to shell configuration file. There are <a href= "http://stackoverflow.com/questions/603785/environment-variables-in-mac-os-x"> multiple configuration files for Bash shell including <code>.profile</code>, <code>.bashrc</code>, <code>/etc/profile</code></a>. For me, I used <code>$HOME/.bashrc</code>:</p> <pre> <code>## Method 1: Set JAVA_HOME to macOS's system Java Home/ which is a symlink pointing to ## /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home as of macOS 10.9.2 ## When there are multiple versions of Java installed, using the /usr/libexec/java_home method below is better. # export JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Home" ## Method 2: Alternatively, set the path using the /usr/libexec/java_home command with a parameter -v to choose specific version of Java ## Use the following to see verbose info about available versions of Java when unsure. ## /usr/libexec/java_home -V ## /usr/libexec/java_home -Vv 1.6 ## Use Java 6 export JAVA_HOME=`/usr/libexec/java_home -v 1.6` ## Use Java 7 # export JAVA_HOME=`/usr/libexec/java_home -v 1.7` ## Use Java 8 # export JAVA_HOME=`/usr/libexec/java_home -v 1.8` </code></pre> <p>So, potentially, one can tweak the lines in method 2 and choose different version to use. Notice that the binary <code>/usr/libexec/java_home</code> is used to determine the Java home directory:</p> <pre><code>$ /usr/libexec/java_home -V Matching Java Virtual Machines (4): 1.8.0, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home 1.7.0_51, x86_64: "Java SE 7" /Library/Java/JavaVirtualMachines/jdk1.7.0_51/Contents/Home 1.6.0_65-b14-462, x86_64: "Java SE 6" /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home 1.6.0_65-b14-462, i386: "Java SE 6" /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home /Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home </code></pre> <p>It seems it recognizes all available JVMs and picks the home directory from the latest version.</p> <h3>Setting <code>JAVA_HOME</code> for Mathematica</h3> <p>I'm a heavy user of <a href= "http://www.wolfram.com/mathematica/">Mathematica</a>. As of Mathematica 9, it is developed based on Java 6 and its Java related functionalities such as J/Link package may not work properly if a different version of Java is used.</p> <p>There are two configurations to set and/or check.</p> <h4><code>JAVA_HOME</code></h4> <p>As of Mathematica 9, verify that Mathematica's <code>$JAVA_HOME</code> is pointing to macOS's system Java's JVM 1.6.*:</p> <pre><code>In[1]:= Import["!echo $JAVA_HOME", "Text"] Out[1]= "/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home" In[2]:= Environment["JAVA_HOME"] Out[2]= "/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home" </code></pre> <p>I'm not sure why the following does not work:</p> <pre><code>In[3]:= Import["!java -version", "Text"] Out[3]= "" </code></pre> <h4><code>CommandLine -&gt; "java"</code></h4> <p>One can <a href= "https://reference.wolfram.com/mathematica/JLink/tutorial/CallingJavaFromMathematica.html"> "install" Java inside Mathematica runtime by the function <code>InstallJava</code> and then use Java classes inside Mathematica programs.</a></p> <p>The <code>InstallJava</code> function or its close relative <code>ReinstallJava</code> has an option called <a href= "https://reference.wolfram.com/mathematica/JLink/tutorial/CallingJavaFromMathematica.html"> <code>CommandLine</code></a>:</p> <pre> <code>CommandLine -&gt; "cmd" use the specified command line to launch the Java runtime, instead of "java" </code></pre> <p>Some examples of that is</p> <pre><code>InstallJava[] InstallJava[CommandLine -&gt; "java"] InstallJava[CommandLine -&gt; "java --Xmx1024m"] </code></pre> <p>The source code in <code>$InstallationDirectory/SystemFiles/Links/JLink/Kernel/InstallJava.m</code> indicates that if <code>CommandLine</code> is not used, it will uses Mathematica's own Java <code>ToFileName[{getJLinkAppDir[], "JLink.app", "Contents", "MacOS"}, "JavaApplicationStub"]</code>. If <code>CommandLine -&gt; "java"</code> is used, make sure it's the right version:</p> <pre><code>In[8]:= Needs["JLink`"] ReinstallJava[CommandLine-&gt;"java"] LoadJavaClass["java.lang.System"] java`lang`System`getProperty["java.version"] Out[9]= LinkObject[java -classpath "/Applications/Mathematica.app/SystemFiles/Links/JLink/JLink.jar" -Xdock:name=J/Link -Xmx256m -Djava.system.class.loader=com.wolfram.jlink.JLinkSystemClassLoader com.wolfram.jlink.Install -init "/tmp/m00000347291",166,4] Out[10]= JavaClass[java.lang.System,&lt;&gt;] Out[11]= 1.6.0_65 </code></pre> <p>If the output of <code>getProperty["java.version"]</code> is not consistent with <code>JAVA_HOME</code>, or if <code>LoadJavaClass["java.lang.System"]</code> issues errors, there must be some problem.</p> <p>See <a href="http://meng6net.localhost/tag/configuration/installing_and_configuring_java_on_mac.nb">the attached notebook containing these testing code</a>.</p> <h4>Methods for starting Mathematica</h4> <h5><code>open -a Mathematica</code></h5> <p>If I start Mathematica with <code>open -a Mathematica</code> from command line, which would lead Mathematica to inherit <code>JAVA_HOME</code> set in <code>.bashrc</code>, I get the correct <code>JAVA_HOME</code> value</p> <pre><code>In[1]:= Import["!echo $JAVA_HOME", "Text"] Out[1]= "/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/\ Home" In[2]:= Environment["JAVA_HOME"] Out[2]= "/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/\ Home" </code></pre> <p>as well as correct version of Java:</p> <pre><code>In[16]:= Needs["JLink`"] ReinstallJava[CommandLine -&gt; "java"] LoadJavaClass["java.lang.System"] java`lang`System`getProperty["java.version"] Out[17]= LinkObject["'/Applications/Mathematica.app/SystemFiles/Links/JLink/JLink.app/Contents/MacOS/JavaApplicationStub' -init \"/tmp/m00000847291\"", 219, 4] Out[18]= JLink`JavaClass["java.lang.System", 0, {JLink`JVM["vm1"],JLink`JVM["vm2"]}, 1, "java`lang`System`", False, True] Out[19]= "1.6.0_65" </code></pre> <p>At the same time Oracle JDK 1.7 and 1.8 are installed on the system.</p> <h5>Double clicking "/Applications/Mathematica.app"</h5> <p>If I start Mathematica by double clicking "/Applications/Mathematica.app" in Finder or a link to it in Dock,</p> <pre><code>ReinstallJava[CommandLine -&gt; "java"] LoadJavaClass["java.lang.System"] </code></pre> <p>issues a <code>LinkObject::linkn</code> error, and <code>Environment["JAVA_HOME"]</code> returns <code>$Failed</code>:</p> <pre><code>In[1]:= Needs["JLink`"] ReinstallJava[CommandLine-&gt;"java"] LoadJavaClass["java.lang.System"] java`lang`System`getProperty["java.version"] Out[2]= LinkObject[java -classpath "/Applications/Mathematica.app/SystemFiles/Links/JLink/JLink.jar" -Xdock:name=J/Link -Xmx256m -Djava.system.class.loader=com.wolfram.jlink.JLinkSystemClassLoader com.wolfram.jlink.Install -init "/tmp/m00000155721",125,4] During evaluation of In[1]:= LinkObject::linkn: Argument LinkObject[java -classpath "/Applications/Mathematica.app/SystemFiles/Links/JLink/JLink.jar" -Xdock:name=J/Link -Xmx256m -Djava.system.class.loader=com.wolfram.jlink.JLinkSystemClassLoader com.wolfram.jlink.Install -init "/tmp/m00000155721",125,4] in LinkReadyQ[LinkObject[java -classpath "/Applications/Mathematica.app/SystemFiles/Links/JLink/JLink.jar" -Xdock:name=J/Link -Xmx256m -Djava.system.class.loader=com.wolfram.jlink.JLinkSystemClassLoader com.wolfram.jlink.Install -init "/tmp/m00000155721",125,4]] has an invalid LinkObject number; the link may be closed. &gt;&gt; During evaluation of In[1]:= LinkObject::linkn: Argument LinkObject[java -classpath "/Applications/Mathematica.app/SystemFiles/Links/JLink/JLink.jar" -Xdock:name=J/Link -Xmx256m -Djava.system.class.loader=com.wolfram.jlink.JLinkSystemClassLoader com.wolfram.jlink.Install -init "/tmp/m00000155721",125,4] in LinkConnectedQ[LinkObject[java -classpath "/Applications/Mathematica.app/SystemFiles/Links/JLink/JLink.jar" -Xdock:name=J/Link -Xmx256m -Djava.system.class.loader=com.wolfram.jlink.JLinkSystemClassLoader com.wolfram.jlink.Install -init "/tmp/m00000155721",125,4]] has an invalid LinkObject number; the link may be closed. &gt;&gt; During evaluation of In[1]:= LinkObject::linkn: Argument LinkObject[java -classpath "/Applications/Mathematica.app/SystemFiles/Links/JLink/JLink.jar" -Xdock:name=J/Link -Xmx256m -Djava.system.class.loader=com.wolfram.jlink.JLinkSystemClassLoader com.wolfram.jlink.Install -init "/tmp/m00000155721",125,4] in LinkReadyQ[LinkObject[java -classpath "/Applications/Mathematica.app/SystemFiles/Links/JLink/JLink.jar" -Xdock:name=J/Link -Xmx256m -Djava.system.class.loader=com.wolfram.jlink.JLinkSystemClassLoader com.wolfram.jlink.Install -init "/tmp/m00000155721",125,4]] has an invalid LinkObject number; the link may be closed. &gt;&gt; During evaluation of In[1]:= General::stop: Further output of LinkObject::linkn will be suppressed during this calculation. &gt;&gt; During evaluation of In[1]:= InstallJava::fail: A link to the Java runtime could not be established. &gt;&gt; During evaluation of In[1]:= LoadJavaClass::fail: Java failed to load class java.lang.System. &gt;&gt; Out[3]= $Failed Out[4]= java`lang`System`getProperty[java.version] </code></pre> <p>I don't fully understand what causes the <code>LinkObject::linkn</code> error and its possible relation to <code>JAVA_HOME</code>. My guess is this is due to <code>JAVA_HOME</code> not being correctly set for Mathematica and and somewhere in the processing an implied and incorrect Java home is used, possibly computed by</p> <pre><code>$ /usr/libexec/java_home /Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home </code></pre> <p>For both ways of starting Mathematica,</p> <pre> <code>ReinstallJava[] (* notice there is NO CommandLine -&gt; "java" used *) LoadJavaClass["java.lang.System"] </code></pre> <p>works. This is probably expected as <code>CommandLine -&gt; Automatic</code> seems to lead Mathematica to use its own Java <code>$InstallationDirectory/SystemFiles/Links/JLink/JLink.app/Contents/MacOS/JavaApplicationStub</code>. The logic controlling this can be found in source file <code>$InstallationDirectory/SystemFiles/Links/JLink/Kernel/InstallJava.m</code>.</p> <p>So if you have multiple Java installed and if <code>/usr/libexec/java_home</code> finds the wrong version of Java home directory for Mathematica (i.e. not 1.6.*)</p> <pre><code>$ /usr/libexec/java_home /Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home </code></pre> <p>you'll need to start Mathematica with <code>open -a Mathematica</code>.</p> <h5>Wrapper application OpenMathematicaAppFromCLIWithJava1.6.app made with Automator</h5> <p>If you prefer double clicking an icon on Dock than opening terminal and typing <code>open -a Mathematica</code>, you can create an application equivalent to setting <code>JAVA_HOME</code> and <code>open -a Mathematica</code> and put a link to it in Dock.</p> <p>1) Start /Applications/Automator.app by double clicking it;</p> <p>2) Choose "Application" and press button "Choose";</p> <p>3) In "Variables" input field, type "Run Shell Script", and double click it;</p> <p>4) In the RHS window, replace the default content 'cat' with</p> <pre><code>export JAVA_HOME=$(/usr/libexec/java_home -v 1.6*) open -a "/Applications/Mathematica.app" </code></pre> <p>5) Save it somewhere as a standalone application. I chose name <code>OpenMathematicaAppFromCLIWithJava1.6.app</code>;</p> <p>6) Optionally, you can make the icon of <code>OpenMathematicaAppFromCLIWithJava1.6.app</code> same as <code>Mathematica.app</code>'s by clicking "Get Info" in the context menu of the two applictions, and copy the icon in the top left part of the pop-up window by selecting the icon by clicking on it and <kbd>Cmd</kbd>-<kbd>C</kbd> and <kbd>Cmd</kbd>-<kbd>V</kbd>;</p> <p>7) Drag <code>OpenMathematicaAppFromCLIWithJava1.6.app</code> onto Dock to create a link to it;</p> <p>8) Start Mathematica by clicking the icon on Dock, and verify that <code>Environment["JAVA_HOME"]</code> and <code>getProperty[java.version]</code> behave correctly.</p> <h2>Configuring IDEs (virtually Eclipse and IntelliJ IDEA)</h2> <p>In IDEs such as Eclipse and IntelliJ IDEA, it's actually easier to use multiple versions of JDK, and different versions for different projects/modules. It's fairly easy to find the related documentation. My understanding is IDEs' JDK version does not have to be same as command-line <code>java</code>. They are basically different and unrelated Java development environments.</p> <p>A relatively more complex issue is, as Eclipse and IntelliJ IDEA themselves are Java applications, what JVM are they running off of? And do you possibly want to start them using Oracle Java?</p> <p>Here are some information:</p> <h3>IntelliJ IDEA</h3> <p><a href= "https://intellij-support.jetbrains.com/entries/23455956-Selecting-the-JDK-version-the-IDE-will-run-under"> Selecting the JDK version the IDE will run under</a>.</p> <h3>Eclipse</h3> <p>(This part about Eclipse is a drat and needs verification.)</p> <h4>Method 1: <code>-vm &lt;Oracle JDK 1.7 Home/ path&gt;</code> in Eclipse.ini</h4> <p>Add something like</p> <pre> <code>-vm /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/ </code></pre> <p>at the end of eclipse.ini.</p> <h4>Method 2: shell script + Automator application</h4> <p>Make a shell script that takes care of <code>JAVA_HOME</code> and JVM:</p> <pre><code>#!/bin/sh export JAVA_HOME=$(/usr/libexec/java_home -v 1.7) LAUNCHER_JAR=/Applications/eclipse/plugins/org.eclipse.equinox.launcher_1.2.0.v20110502.jar java \ -showversion \ -XX:MaxPermSize=256m \ -Xms1024m \ -Xmx1024m \ -Xdock:icon=/Applications/eclipse/Eclipse.app/Contents/Resources/Eclipse.icns \ -XstartOnFirstThread \ -Dorg.eclipse.swt.internal.carbon.smallFonts \ -Dosgi.requiredJavaVersion=1.5 \ -jar $LAUNCHER_JAR </code></pre> <p>and then make a wrapper application using Automator.</p> <h2>Installing Oracle JDK from command-line</h2> <ul> <li> <p>Download DMG</p> <p>$ wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u60-b27/jdk-8u60-macosx-x64.dmg"</p> </li> <li> <p>Mount DMG:</p> <p>$ hdiutil mount jdk-8u60-macosx-x64.dmg</p> </li> <li> <p>Install</p> <p>$ sudo installer -pkg /Volumes/JDK\ 8\ Update\ 60/JDK\ 8\ Update\ 60.pkg -dominfo LocalSystem $ sudo installer -pkg /Volumes/JDK\ 8\ Update\ 60/JDK\ 8\ Update\ 60.pkg -target LocalSystem</p> </li> </ul> <h2>References</h2> <ul> <li> <p><a href= "http://www.cc.gatech.edu/~simpkins/teaching/gatech/cs2340/guides/java7-macosx.html"> Christopher L. Simpkins,〈Java 7 on macOS〉</a></p> </li> <li> <p><a href= "http://www.java.com/en/download/faq/java_mac.xml">〈java.com documentation: Information and system requirements for installing and using Mac Java 7〉</a></p> </li> <li> <p><a href= "http://mathiasbynens.be/notes/shell-script-mac-apps">Mathias Bynens, 〈How to create simple Mac apps from shell scripts〉</a></p> </li> <li> <p><a href= "http://stackoverflow.com/questions/10352715/how-do-i-run-eclipse-using-oracles-new-1-7-jdk-for-the-mac"> Stackoverflow.com thread 〈How do I run Eclipse using Oracle's new 1.7 JDK for the Mac?〉</a></p> </li> <li> <p><a href= "http://stackoverflow.com/questions/603785/environment-variables-in-mac-os-x"> Stackoverflow.com thread 〈Environment variables in macOS〉</a></p> </li> <li> <p>docs.oracle.com, <a href= "https://docs.oracle.com/javase/8/docs/technotes/guides/install/mac_jdk.html"> 〈JDK 8 Installation for OS X〉</a></p> </li> </ul> Installing and configuring LaTeX http://meng6net.localhost/computing/installing_and_configuring/installing_and_configuring_LaTeX/ http://meng6net.localhost/computing/installing_and_configuring/installing_and_configuring_LaTeX/ computing configuration documentation draft installation note software Tue, 16 May 2017 23:59:39 +0000 2020-05-15T01:57:52Z <ul> <li>Last verified as of <ul> <li>macOS: 2020-5-14 and macOS 10.14.6 and MacTex 2020.0407;</li> <li>Linux: 2015-9 and Ubuntu.</li> </ul> </li> </ul> <h2>Linux</h2> <p>Tested on Ubuntu Linux 14 as of 2015-9.</p> <pre><code>sudo apt-get install texlive-full </code></pre> <h3>Install extensions using <code>apt-get</code></h3> <p>How to search the package that contains file <code>standalone.sty</code> and install it:</p> <pre><code>$ sudo apt-get install apt-file $ apt-file update $ apt-file search standalone.sty texlive-latex-extra: /usr/share/texlive/texmf-dist/tex/latex/standalone/standalone.sty $ sudo apt-get install texlive-latex-extra </code></pre> <h2>macOS</h2> <h3>Veify if you already have LaTeX and needs an update</h3> <p><a href="https://www.tug.org/texlive/">As of May 14, 2020, the latest 'tex-live' release is 'Tex Live 2020'</a>.</p> <p>I verified on my computer that I have an older version installed:</p> <pre><code>$ which latex /Library/TeX/texbin/latex $ latex --version pdfTeX 3.14159265-2.6-1.40.16 (TeX Live 2015) kpathsea version 6.2.1 Copyright 2015 Peter Breitenlohner (eTeX)/Han The Thanh (pdfTeX). There is NO warranty. Redistribution of this software is covered by the terms of both the pdfTeX copyright and the Lesser GNU General Public License. For more information about these matters, see the file named COPYING and the pdfTeX source. Primary author of pdfTeX: Peter Breitenlohner (eTeX)/Han The Thanh (pdfTeX). Compiled with libpng 1.6.17; using libpng 1.6.17 Compiled with zlib 1.2.8; using zlib 1.2.8 Compiled with xpdf version 3.04 </code></pre> <p>I no longer remember how I installed it or if I used homebrew or <a href="https://www.tug.org/mactex/">'MacTeX'</a>. But I will just re-install it using Homebrew assuming I don't really need to carefully uninstall the current files.</p> <h3>Uninstalling previous versions of MacTeX</h3> <p>Uninstall previous versions of MacTeX[^mactexuninstalling]:</p> <pre> <code>$ ls -la /usr/local/texlive/ drwxr-xr-x 20 root wheel 640B May 8 2019 2015/ drwxr-xr-x 20 root wheel 640B May 8 2019 2017/ drwxr-xr-x 20 root wheel 640B May 8 2019 2019/ drwxr-xr-x 9 meng admin 288B Oct 27 2017 texmf-local/ $ du -hs /usr/local/texlive/2015 4.3G $ du -hs /usr/local/texlive/2017 5G $ du -hs /usr/local/texlive/2019 6.3G $ sudo rm -rf /usr/local/texlive/2015 /usr/local/texlive/2017 /usr/local/texlive/2019 </code></pre> <ul> <li> <p>Remove the GUI application</p> <pre><code> rm -rf /Applications/TeX </code></pre></li> <li> <p>Re-install MacTeX</p> <pre><code> brew cask install mactex </code></pre></li> </ul> <h3>Installing MacTex using homebrew</h3> <p>Homebrew tells you to install MacTeX if you simply search for the keyword 'tex':</p> <pre><code>$ brew search tex asciitex blahtexml itex2mml latexila libtextcat rtf2latex2e texinfo vilistextum bibtex2html gettext ✔ latex2html latexml opendetex texapp texmath bibtexconv html2text latex2rtf libdrawtext ptex texi2html ✔ textql caskroom/cask/tex-live-utility caskroom/fonts/font-tex-gyre-adventor caskroom/fonts/font-tex-gyre-heros caskroom/fonts/font-tex-gyre-cursor caskroom/fonts/font-tex-gyre-termes caskroom/fonts/font-tex-gyre-pagella-math caskroom/fonts/font-tex-gyre-chorus caskroom/fonts/font-tex-gyre-schola caskroom/fonts/font-tex-gyre-bonum caskroom/fonts/font-tex-gyre-pagella If you meant "tex" specifically: Installing TeX from source is weird and gross, requires a lot of patches, and only builds 32-bit (and thus can't use Homebrew dependencies) We recommend using a MacTeX distribution: https://www.tug.org/mactex/ You can install it with Homebrew-Cask: brew cask install mactex </code></pre> <p>I will just install using</p> <pre><code>$ brew cask install mactex ==&gt; Downloading http://mirror.ctan.org/systems/mac/mactex/mactex-20170524.pkg Already downloaded: /Users/meng/Library/Caches/Homebrew/Cask/mactex--20170524.pkg ==&gt; Verifying checksum for Cask mactex ==&gt; Installing Cask mactex ==&gt; Running installer for mactex; your password may be necessary. ==&gt; Package installers may write to any location; options such as --appdir are ignored. Password: ==&gt; installer: Package name is MacTeX-2017 ==&gt; installer: Upgrading at base path / ==&gt; installer: The upgrade was successful. 🍺 mactex was successfully installed! &gt;&gt;&gt; elapsed time 9m39s $ which latex /Library/TeX/texbin/latex $ latex --version pdfTeX 3.14159265-2.6-1.40.18 (TeX Live 2017) kpathsea version 6.2.3 Copyright 2017 Han The Thanh (pdfTeX) et al. There is NO warranty. Redistribution of this software is covered by the terms of both the pdfTeX copyright and the Lesser GNU General Public License. For more information about these matters, see the file named COPYING and the pdfTeX source. Primary author of pdfTeX: Han The Thanh (pdfTeX) et al. Compiled with libpng 1.6.29; using libpng 1.6.29 Compiled with zlib 1.2.11; using zlib 1.2.11 Compiled with xpdf version 3.04 </code></pre> <h2>Installing extensions using <code>tlmgr</code></h2> <p>Alternatively, if the TeX system is not installed via Ubuntu Linux's package management system and <code>apt-get</code>, one can use <code>tlmgr</code> to install and update the TeX extensions:</p> <pre><code>tlmgr update --self --all tlmgr install standalone tlmgr update standalone </code></pre> <h3>Linux</h3> <p>The TeX package management tool <code>tlmgr</code> itself is part of <code>texlive-base</code> and can be installed via</p> <pre><code>sudo apt-get install texlive-base </code></pre> <h3>macOS</h3> <p>On macOS, installing MacTeX using homebrew will install tlmgr as well.</p> <h2>References</h2> <p>[^mactexuninstalling] tug.org/mactex. "Uninstalling". <a href= "https://www.tug.org/mactex/uninstalling.html">https://www.tug.org/mactex/uninstalling.html</a>.</p>