Basic developer setup Aug 20 2018
I have always been fascinated by other professions that have physical workshops, imagine a room full of neat rows of tools, with everything at hand, just having everything on its own places makes you want to create and build new things with your tools. The same applies to software, we should have all of our tools clean and sorted, we should know where everything is and where to expect to find a piece of configuration we need to modify.
Sadly, we are never told how to keep our tools or how to build our own workshop. This is mostly because we lack a master-apprentice model that is common for other crafts, but that is the topic of another post. Imagine going into a workshop where everything is piled up without any structure, what would you think of that craftsman? Imagine our clients coming to see our development environment, what would they find? A tidy workshop or a messy room?
I’m a firm believer in: “how you do anything is how you do everything”. If you keep a clean development environment you’ll probably produce clean code. I will share with you a basic scheme to follow in the initial setup of your development environment and a couple of tips on how to keep everything in order and have a tidy workspace.
Table of Contents
- Create a useful directory structure
- Use a package manager
- Use a version manager for your programming language
- Build your own setup script
- Now the actual setup script
- Final thoughts
A big number of applications rely on having a configuration file for the user, the configuration file has been normally saved in dot files, historically the configuration file name’s start with a dot (.), hence the name dotfiles. Because normally they are hidden files, which only means that the graphical file browser chooses not to display them by default, so most applications would look for them in the user’s home directory.
Have a structure for your configuration
I wish I could tell you just create a .config (as proposed by the (XDG Base Directory Specification ) [https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html]) on your home directory, follow that structure and you’ll have a clean home directory, but not all applications follow this convention and a lot of applications will pollute your home directory with lots of dot files. I haven’t found a good way to clean this messy part but at least let us not be the cause of more entropy, have your own configurations in one place.
Version control your dotfiles
This is an important one, when you want to replicate your configurations on some other environment you’ll have them easily available.
Create a useful directory structure
You could start with a basic structure that will allow you to know where everything is, for example:
1 2 3 4 Documents/ ├── Development ├── Personal └── Work
That way everything is compartmentalized, subdivide it as much as you need and feel it is useful for example:
Inside the Work, directory create a directory per client:
1 2 3 4 5 6 7 Documents/Work ├── Client 1 ├── Client 2 ├── Client 3 ├── ... ├── Client 1023 └── Client 1024
Not a big surprise there, I like to have a folder where tinker with different programming language, frameworks, etc. that would be the Developer folder, where I would have everything segregated by programming language/technology/category just to give me an idea of what I would find inside, and it’ll make it easy to search for a project. For example, if I were looking for the code I wrote in fish-script to handle the Tmux navigation, inside the directory
fish would be a safe bet.
Whatever you do, make it easy for you to find later, you don’t want ambiguous names that will be hard to decipher later.
An example directory structure will look like the following:
Use a package manager
For a package manager, I use homebrew, the formulae are written in ruby, so that makes it easy for me if I need to add a new library or tool or just to understand how some package was compiled, it is very easy to look at the ruby code and figure it out and/or build your own custom packages.
It really doesn’t matter which package manager you use, macports, homebrew, fink, etc. use something to have a consistent development environment, this way when you want to check a configuration file you’ll know where to find it. You won’t be thinking is it in /etc or /var/local/etc/ or /Library/ or was it in some obscure directory, you will just follow the convention of your package manager of choice and easily find it.
Use a version manager for your programming language
Nowadays I find myself developing in Ruby for most of my projects, so I use rbenv to manage all the versions of ruby and a plugin to manage the gemsets. The problem of installing your programming language compiler (interpreter, etc) and libraries in the global scope is that if/when you are working in more than one project you’ll soon find yourself having to use different versions of a library or language, and if you have everything on the global scope, things start to get messy.
Use a version manager, there are version managers for pretty much every language use them, the time it will take you to do the first configuration will be worth it, and hopefully, you’ll seldom do a full install again (or you’ll use a setup script to make installation simple, well talk about that next).
Build your own setup script
Build a setup script that will install all the basic software you need, it doesn't have to be very complex, it could be something as simple as using
brew install to install all the software you use. I use homebrew to install the libraries and servers I need and I use brew cask to install some of the apps.
Get a list of all the software you normally use
Before you can install everything, you should know what everything means. Get a list of all the software you normally use, you can use your package manager to do that.
You can obtain a list of all the software you have installed via homebrew (use the leaves you probably don’t want all the dependencies).
1 brew leaves
This will give you a list like this:
1 2 3 4 5 6 ack bash bash-completion cmake ctags dos2unix
Then go to your editor, and add brew install at the beginning of your line, if you are using vim:
1 :%s/^/brew install /g
That will produce:
1 2 3 4 5 6 7 brew install ack brew install asciidoc brew install asciinema brew install bash brew install bash-completion brew install cmake brew install ctags
Check your apps installed via brew cask:
1 brew cask list -1
That will give you a list like:
1 2 3 4 5 6 7 8 9 appcleaner caffeine google-chrome iterm2 keka licecap ngrok spectacle vlc
Add your brew cask install to the beginning of the file as we did in the previous section.
Now you can create your setup script, you could start with a basic bash script, like the following:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 #!/usr/bin/env sh #install software brew install ack brew install asciidoc brew install asciinema brew install bash brew install bash-completion brew install cmake brew install ctags # install apps brew cask install appcleaner brew cask install caffeine brew cask install google-chrome brew cask install iterm2 brew cask install keka brew cask install licecap brew cask install ngrok brew cask install spectacle brew cask install vlc
As you see nothing fancy but it will definitely make things easy when you change computers or want to recreate your setup, just try to keep this script up to date and you’ll have an easy time rebuilding your setup.
Now the actual setup script
That script was too basic, we should create something more close to what we would define as a basic setup script. Let's start by creating a script that will clone your configuration repository and create the links so the changes take effect. This should be a simple script nothing too complicated, with the years it might grow to be a complete finetuned machine but for now, let's at least have a consistent way of replicating our setup.
Here is a basic script you could take as a basis for your setup script.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 #!/usr/bin/env sh dotfile_dir="$HOME/Documents/Development/configuration/dotfiles" git_repo="https://github.com/rderik/dotfiles.git" if [ -d $dotfile_dir ]; then echo "$dot_file already exists exists" else echo "Doesn't exists" mkdir -p $dotfile_dir git clone $git_repo $dotfile_dir if [ $? -eq 0 ]; then echo "Repo cloned successfully!" if [ ! -d ~/.config/bash ]; then mkdir -p "$HOME/.config/bash" fi ln -s "$dotfile_dir/config/bash/bash_aliases" "$HOME/.config/bash/bash_aliases" ln -s "$dotfile_dir/config/bash/bash_exports" "$HOME/.config/bash/bash_exports" ln -s "$dotfile_dir/config/bash/bash_extra" "$HOME/.config/bash/bash_extra" ln -s "$dotfile_dir/config/bash/bash_path" "$HOME/.config/bash/bash_path" ln -s "$dotfile_dir/config/bash/bash_prompt" "$HOME/.config/bash/bash_prompt" #install homebre /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" #install homebrew packages brew install ack brew install asciidoc brew install asciinema brew install bash brew install bash-completion brew install cmake brew install ctags # install apps brew cask install appcleaner brew cask install caffeine brew cask install google-chrome brew cask install iterm2 brew cask install keka brew cask install licecap brew cask install ngrok brew cask install spectacle brew cask install vlc fi fi
Congratulations now you have a basic setup that you can replicate, keep improving it. Every time you add a new tool to your workflow, add it to your setup script, adapt it to what you need, remove what you are no longer using. Keep your workshop clean.
This was a very quick overview of where to start setting up your development environment, but I hope it gives you a good idea of where to start. There are still many topics to discuss, for example:
- Text editors
- Terminal multiplexers
- How to keep a work journal/notes
I’ll write about them sometime in the future, let me know if you have any questions, or if you want me to write about a specific topic.
In the meantime, remember we are craftsmen and as such we should hold ourselves to a higher standard, keep your workplace clean, your tools sharp and use your skills to change the world.