First Login on Digital Ocean with FreeBSD

Although I’m a longtime Linode and (Slackware) Linux user, I finally decided to get around to trying Digital Ocean with a FreeBSD droplet.  The process was not as easy as advertised, but I was finally able to login!  That took some doing.

After creating the droplet and domain records, I decided to go with the SSH login (vs. having a temporary root password emailed to me).

First you create SSH keys.  On OSX, I went to ~/.ssh directory, and did the following:

ssh-keygen -t rsa

Copy it to the clipboard:

pbcopy < ~/.ssh/id_rsa.pub

The important thing to note here is that your SSH key must be added to the DO dashboard **before** you create the droplet.

The id_rsa file must have the following permissions set:

chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_rsa

Otherwise, when you attempt to login to DO, you’ll be greeted (as I was) with a screen that looks like this:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: UNPROTECTED PRIVATE KEY FILE! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0640 for '/Users/myusername/.ssh/id_rsa' are too open.
It is recommended that your private key files are NOT accessible
by others.
This private key will be ignored.
bad permissions: ignore key: /Users/myusername/.ssh/id_rsa

Setting correct permissions will also help avoid popups requesting a password for the id_rsa key on OSX.

Then, just login as the freebsd user. This is a superuser which has the SSH authentication tied to it.

ssh freebsd@yourIP

And you’re good to go!

References:
How to Configure SSH Key-based Authentication on a FreeBSD Server (comments are most relevant)
Password Dialog Appears When SSH Private Key Permissions are Set to 600

Posted in remote.config | Tagged , , | Leave a comment

Using Racket in Emacs on OSX

One of my long-term goals is to work my way through How to Design Programs using Racket, and I recently started the Intro to Systematic Program Design on Coursera, which uses both HtDP and Racket. Naturally I thought to myself, with all the zeal of the newly converted: “Hey, instead of using the super easy/nice DrRacket GUI, let’s work through this course in Emacs using some sort of Racket mode! It’ll be easy!”

Dear future self/reader: this ended up being an 8+ hour detour into getting the damn thing to work. I hope this serves as some sort of cautionary tale about something or other.

I first installed Greg Hendershott’s racket-mode using M-x package install RET racket-mode. I start a test.rkt file and all appears well. Until I tried to run that code through the REPL, accessed via C-M-F5. That resulted in Searching for program: no such file or directory, racket errors.

The crux of my problem was two-fold: first, Emacs does not automatically pick up shell/bash environment variables (paths) in OSX; second, I wasn’t able to find the racket binary on my system after installing Racket 6.1.1. It took me way too long to figure that out. I ended up installing Racket 6.2.0.2 (a development version), which solved that problem. [Note: I don’t think it’s an issue with 6.1.1 – I think that the binary was accidentally deleted at some point.]

That got rid of the ‘racket not found’ problem, but a new error appeared when I tried to invoke the REPL: unbound identifier in module error! What fresh hell is this? (There was another error prior to this one, but I was so frazzled and frustrated at that point I wasn’t logging

So:

Install Racket.
Ensure that /Applications/Racket vX.Y.Z/bin/racket exists.

In ~.bash_profile, add:

PATH=/Applications/Racket\ vX.Y.Z/bin:$PATH
(The backwards slash after Racket escapes the space in the path.)

In Emacs, install exec-path-from-shell. This will allow Emacs to read the system shell’s path. To .emacs (or init.el), add:

(when (memq window-system '(mac ns))
(exec-path-from-shell-initialize))

Finally, make sure that you preface your .rkt files with the header #lang racket.

See also:

Path and Exec Path Set but Emacs Doesn’t Find Executable.

Posted in emacs, local.config, Racket | Leave a comment

Getting Started with Emacs

I’ve been reading about, mucking around with, and generally doing nothing with emacs for literally years. Every time I’d start, I’d quickly get overwhelmed with all the key chords, modes, confusing terminology, and just generally insane complexity (which perversely are also part of the appeal). So although I’ve long fantasized about being an EMACS WIZARD, I’ve done very little to advance that cause. Because, reasons laziness. I even started thinking that Sublime Text might be an acceptable substitute.

But no more!

Today was the day I made my first real attempt at learning Emacs. First, I went through the builtin tutorial. This is absolutely essential to get started with Emacs – it gets you used to using the keyboard/key-bindings to move around the screen, killing and yanking (cut and pasting), and other basic commands. I’d started this thing several times in the past, but my eyes quickly glazed over with the large screen of text, but honestly, I just hadn’t given it a chance. Today I did, and for some reason the usual eye-glazing didn’t occur. I read avidly, did all the interactive exercises, and got a ton out of it. All in about 45 minutes or so.

Next up was Chris Forno’s awesome introductory emacs videos. They average about 10 minutes apiece, and cover all the essentials. It’s important to follow along with what he’s doing in your own Emacs, so that you get the full benefit of his knowledge. As I result, I ended up with a somewhat customized Emacs (Solarized theme, Consolas font), *finally* understood how to switch buffers easily, and removed the toolbars from my Emacs to force me to use the keyboard:

mouse-unfriendly zone

 

All told, I probably spent about 8 hours in Emacs, doing the tutorial, following the videos, and general futzing around.  That’s the most time I’ve spent in a concentrated effort to actually start learning the damn thing.  It definitely reinforced the idea of learning by doing – that reading/watching videos isn’t the one true way. I feel more comfortable in Emacs than I ever have (which isn’t saying much, but it’s a start), and finally feel that I’m starting to ‘get’ it on more than a theoretical level.  All of ‘the advanced, self-documenting, customizable, extensible editor’ 1 stuff is meaningless until you really see it in action.

Goals:2

  1. use Emacs every day
  2. work up to using it for JS coding
  3. read the entire manual. Blog series potential!
  4. learn to use Org-mode.
  5. Blog about learnings.
  6. Maybe: learn me some Emacs Lisp programming.
Posted in emacs | Leave a comment

Installing NVM, Node.js, and NPM on Yosemite

There are several ways to install Node.js on Yosemite:

  1. install the package from the Node.js site,
  2. install via brew install node,
  3. and install via nvm, the Node Version Manager.

Naturally, I’ve decided to go with the least straightforward approach, which is installing via nvm. After spending too much time on the subject, it appears that Homebrew is a perfectly acceptable way to install Node, although that hasn’t always been the case. Manual installation is also a fine way to install it. However, I chose to nvm primarily for its versioning capabilities; that is, it works much like rvm/rbenv in that it can download and manage multiple versions of Node. Now, I’m not sure that I’ll ever need to keep track of multiple versions of Node, but it’s nice to have the option.

Prerequisites:

brew install wget
brew install git

Install NVM:

git clone https://github.com/creationix/nvm.git ~/.nvm && cd ~/.nvm && git checkout `git describe --abbrev=0 --tags`

in order to have it available upon login, add the following to .bash_profile:

source ~/.nvm/nvm.sh

NVM commands:

to see what’s currently installed:

nvm ls

to see what versions of Node are available for install:

nvm ls-remote

Install Node:

once you’ve looked at which versions are available,

nvm install x.x.x (where x.x.x is the version number)

alternately, simply

nvm install stable | unstable depending on your preference.

to set as default:

nvm use stable

to confirm:
nvm ls
node -v

Install NPM:

just kidding, NPM is installed automatically with Node.
npm -v

References:

Installation and use of NVM: NVM
StackOverflow discussion on homebrew vs manual installation: Installing Node.js – pros/cons of using Brew vs manually managing?

Posted in JavaScript, local.config, NodeJS | Leave a comment

Building Emacs from Source on Yosemite

I just did a clean install of Yosemite. While reviewing my previous posts on getting up and running, I noticed some errors/missing information while following my own directions. I’ve edited those posts for clarity/omissions; however, my previous method of installing emacs via homebrew has been superceded by building it from source. This post details the steps to do so. It takes a bit longer, but allows me to keep up with current development. Caveat: following the master git repo of any software can potentially lead to a unstable/unusable build.

Also, rather than try to install every possible thing to cover every possible use case, I’ve moved to installing things as necessary. I’m a newbie to emacs, so my previous homebrew install of the Cocoa app included just about every possible configuration option; this one is much more minimal.

1. Prequisites:

-Xcode
-git
-imagemagick (allows image viewing)
-gnutls (allows communication via SSL, TLS, amd DTLS)
-autoconf
-automake

Git, imagemagick and gnutls can all be installed via homebrew. The last 2 no longer come bundled with Xcode so must be manually installed. This can be done either through brew install autoconf and brew install automake, or by compiling from source:

autoconf:
cd /tmp
curl -O http://ftp.gnu.org/gnu/autoconf/autoconf-latest.tar.gz
tar xf autoconf-latest.tar.gz
cd autoconf-*/
./configure
make
sudo make install

automake:
cd /tmp
curl -O http://ftp.gnu.org/gnu/automake/automake-1.14.tar.gz
tar xf automake-1.14.tar.gz
cd automake-1.14
./configure
make
sudo make install

2. get the source:
git clone git://git.savannah.gnu.org/emacs.git
cd emacs

3. build Emacs.app:
make configure
./configure –with-ns CFLAGS=”-I /usr/local/include/libxml2″

(As of 22 June 2015, –with-ns is no longer necessary)

./configure CFLAGS="-I /usr/local/include/libxml2"
make install

open -R nextstep/Emacs.app

Drag this to Applications to find in Launchpad.

updating and rebuilding:
# discard stuff from last build
git reset --hard

# delete all of the last build stuff
git clean -xdf

git pull
Delete the app from Applications, then follow steps from #3.

References:
Building Emacs 24.4 from Source on the Mac, Spike Ilacqua.
Build Emacs for OSX, Sebastien Gross.
Building Emacs from Git Repository, Xah Lee.
Configure with libxml2, by Irreal.

comment by Offby1, referencing:
commit d97fbcbedce8f36050af7a55d34c6ed50c99507c
Author: Glenn Morris <rgm@gnu.org>
Date: 2015-06-22 22:03:33 -0400
* configure.ac (--with-ns): Enable by default on OS X.

Posted in emacs, local.config | Leave a comment

Configuring Apache and PHP on Yosemite

In order to get PHP working with Apache, I needed to add the following code to /usr/local/etc/apache2/2.4/httpd.conf:

In the DirectoryIndex:

<IfModule dir_module>
    DirectoryIndex index.html index.php
</IfModule>

In the LoadModules section:

LoadModule php5_module /usr/local/opt/php56/libexec/apache2/libphp5.so

After restarting Apache, my test.php file was not displaying phpinfo() data, so I had to add the following right after the LoadModule:

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

References:
Installing LAMP stack on OSX Mavericks with Homebrew

Posted in Uncategorized | Leave a comment

Installing MariaDB and Updating PHP on Yosemite

Continuing from my previous post about updating Apache.

Why MariaDB and not MySQL? See this interview with Michael Widenius, founder of both MySQL and MariaDB.

O. Clean up borked MySQL install

My first attempt to install MySQL via homebrew led to various errors and whatnot, so I uninstalled it via brew uninstall mysql. It turns out that this alone won’t completely cleanup the installation, so first I needed to clean out the remaining files:


sudo rm /usr/local/mysql
sudo rm -rf /usr/local/mysql*
sudo rm -rf /Library/StartupItems/MySQLCOM
sudo rm -rf /Library/PreferencePanes/My*
sudo [emacs/nano/vi] /etc/hostconfig (Remove line MYSQLCOM=-YES)
sudo rm -rf /Library/Receipts/mysql*
sudo rm -rf /Library/Receipts/MySQL*
sudo rm -rf /var/db/receipts/com.mysql.*
sudo rm -rf /tmp/mysql.sock

After all this, I checked to see whether it was running:

ps -ax | grep mysql

and it was!

9958 ttys000 0:17.58 mysqld
11576 ttys002 0:00.00 grep mysql

Kill the process with

kill -9 {PID} - in this case, 9958

During the process of tracking down all this info, I found the interview with Michael Widenius and decided to go with MariaDB. Now we’re ready!

1. Install MariaDB:

brew install mariadb
unset TMPDIR
mysql_install_db
mysql_secure_installation

That will take you through the process of removing anonymous users, setting up a root password and user, etc.

Then just:
mysql -uroot to log in.

2. Upgrading PHP

Yosemite comes with PHP 5.5 installed. As of this writing, the latest stable version of PHP is 5.6.2. There are a couple of ways to upgrade, one involving Homebrew/MacPorts and other using a script provided by Marc Liyanage. Since I’ve installed/upgraded everything else via Homebrew, I’m going to continue on that road.

First, enable some additional taps:

brew tap homebrew/dupes
brew tap josegonzalez/homebrew-php
brew tap homebrew/versions

I then used the following command to install PHP 5.6:

brew install php56 --homebrew-apxs --with-apache --with-homebrew-curl --with-homebrew-openssl --with-phpdbg --with-tidy --with-homebrew-libxslt --without-snmp

Please note that the –without-snmp arg is recommended by Homebrew due to a bug with –with-homebrew-openssl, which is current as of 30 October 2014.

Ensure that the correct PHP is being used on the command line by adding the following to .bash_profile:

export PATH="$(brew --prefix homebrew/php/php56)/bin:$PATH"

To start PHP 5.6 at login:

mkdir -p ~/Library/LaunchAgents
ln -sfv /usr/local/opt/php56/*.plist ~/Library/LaunchAgents

References

StackOverflow discussion on removing MySQL from MacOSX

Homebrew-PHP repository notes

–without-snmp bug discussion

Posted in local.config | Tagged , , | Leave a comment

Terminally Pretty

Fancyin’ up the ole iTerm2.

Install Consolas font:

brew install cabextract
cd ~/Downloads
mkdir consolas
cd consolas
curl -O http://download.microsoft.com/download/f/5/a/f5a3df76-d856-4a61-a6bd-722f52a5be26/PowerPointViewer.exe
cabextract PowerPointViewer.exe
cabextract ppviewer.cab
open CONSOLA*.TTF
# press Install font. That is all.

Thanks to Alexander Zhuravlev.

3. Install Solarized theme:

git clone git://github.com/altercation/solarized.git

See Nicolas Heny’s link below for details on how to set iTerm2’s preferences to use both Consolas and Solarized.

3. dotfiles for color and aliases:

cd ~
curl -O https://raw.githubusercontent.com/nicolashery/mac-dev-setup/master/.bash_profile
curl -O https://raw.githubusercontent.com/nicolashery/mac-dev-setup/master/.bash_prompt
curl -O https://raw.githubusercontent.com/nicolashery/mac-dev-setup/master/.aliases

Via Nicolas Hery’s awesome Mac Dev Setup.

Posted in local.config | Leave a comment

Updating Apache on MacOSX Yosemite

Why? I want to set up a local dev environment for localhosting WordPress, among other things, without installing MAMP.

As of this writing, Yosemite 10.10 comes with the following software versions installed:

Apache - 2.4.9; current: 2.4.10
MySQL/MariaDB: not installed; current: 5.6/10
PHP: 5.5.14; current: 5.6.2

Using Homebrew, I will update the above software. Additionally, I will not be installing phpMyAdmin or similar, since I want to get more comfortable with using MySQL on the command line.

Apache

brew tap homebrew/apache

When I enter the following, I got an error:

brew info homebrew/apache/httpd24
==> Dependencies
Error: No available formula for zlib

Homebrew instructs me to do the following, which fixes the dependency issue:

brew tap homebrew/dupes

brew info homebrew/apache/httpd24 now tells me I need the following dependencies installed:

Required: apr-util, pcre, homebrew/dupes/zlib

Fine.

brew install apr-util
What is apr-util? “The Apache Portable Runtime Utility Library provides a predictable and consistent interface to underlying client library interfaces. This application programming interface assures predictable if not identical behaviour regardless of which libraries are available on a given platform.”

brew install pcre
What is prce? “The PCRE package contains Perl Compatible Regular Expression libraries. These are useful for implementing regular expression pattern matching using the same syntax and semantics as Perl 5.”

brew install zlib
What is zlib? “The Zlib package contains compression and decompression routines used by some programs.”

Finally, install Apache:

brew install httpd24

Well, not quite yet. This generated the following error:

make: *** [install-recursive] Error 1

Homebrew recommends running brew update && doctor and trying again before anything else, which I did, and which corrected the error.

Caveats from Homebrew (for future reference):

To have launchd start httpd24 at login:
mkdir -p ~/Library/LaunchAgents
ln -sfv /usr/local/opt/httpd24/*.plist ~/Library/LaunchAgents
Then to load httpd24 now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.httpd24.plist

I will continue my adventures upgrading MySQL and PHP in another blog post, since this one has gotten rather unwieldly.

References

StackOverflow discussion on upgrading Apache in Mavericks.

apr-util definition from Linux from Scratch.

pcre, from LFS, who has the best file explanations out there.

zlib, from LFS.

Posted in local.config | Tagged , , | 1 Comment

First Things after Clean Install of Yosemite

These are mostly notes to myself. The goal is to set up a basic Ruby on Rails development environment on MacOSX Yosemite.

1. Install Homebrew:

[Homebrew did this automatically, but just in case: install Command Line Tools:
xcode-select --install ]

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

update PATH:

echo 'export PATH=/usr/local/bin:$PATH' >> ~/.bash_profile
source ~/.bash_profile

ensure it’s working:
brew doctor

2. Update tools:

# Install GNU core utilities (those that come with OS X are outdated)
brew install coreutils

# Install GNU `find`, `locate`, `updatedb`, and `xargs`, g-prefixed
brew install findutils

# Install Bash 4
brew install bash

To use this version of bash, you’ll need to change your account’s login shell in System Preferences -> Users & Groups. Right-click on username, select Advanced Options, and change shell to /usr/local/bin/bash. Then restart Terminal.app.

# Install more recent versions of some OS X tools
brew tap homebrew/dupes
brew install homebrew/dupes/grep

3. Setup Git and Github:

brew install git

configure Git:

git config --global user.name "name"
git config --global user.email "my email"

setup SSH key for Github:
cd ~/.ssh
ssh-keygen -t rsa -C "github email"
pbcopy < ~/.ssh/id_rsa.pub

in Github, paste into Settings/SSH Keys.

test that it works:
ssh -T git@github.com

4. Gonna need:
brew install wget
brew install coreutils

5. Install Emacs:
brew install emacs --HEAD --use-git-head --cocoa --with-gnutls --with-rsvg --with-imagemagick
brew linkapps

6. Install rbenv and Ruby

brew install rbenv ruby-build

add rbenv to .bash_profile:

echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile
source ~/.bash_profile

check for most recent Ruby:

rbenv install -l

install Ruby:

rbenv install version-number

set this version of Ruby as default:

rbenv global version-number
ruby -v

7. Install Rails

gem install rails
rbenv rehash
rails -v

References:

General:

Git/Github:  Beginner’s Setup Guide for Ruby, Node.js, Git, Github, and other things on Mac OS X 10.9

Emacs:  StackOverflow discussion on Mac versions of emacs

Ruby, Rails, rbenv: Setup Ruby on Rails on MacOSX 10.10 Yosemite

Posted in local.config | Leave a comment