Skip to content

Instantly share code, notes, and snippets.

@mrhyde
Forked from roblogic/msys2-setup.md
Created February 27, 2019 20:53
Show Gist options
  • Save mrhyde/caca001262988fcb09a5a6a799c38f8e to your computer and use it in GitHub Desktop.
Save mrhyde/caca001262988fcb09a5a6a799c38f8e to your computer and use it in GitHub Desktop.
MSYS2 first time setup

MSYS2 is a minimalist linux/unix shell environment for Windows.

Quote: "A modern replacement for MSYS bringing recent versions of the GNU toolchains, Git and other common Unix command line tools to the Windows platform"

1. Install

Do all the steps listed here: http://msys2.github.io/
(troubleshooting guide here: https://github.com/msys2/msys2/wiki/MSYS2-installation )

2. Set up proxies

Most corporate networks require proxy authentication before connecting to the Net. You can probably skip this section on your home PC.

Edit .bash_profile

Go to your MSYS $HOME directory; in my case it's D:\msys32\home\papesch. Using a text editor, create file .bash_profile, as described below. Save it in UNIX format, then restart MSYS2 to apply the new settings.

#
# .bash_profile example
#
# Example proxy:
# export http_proxy=http://$USERNAME:$PASSWORD@proxy-server-name:1234
# Simpler example without username/password:
export http_proxy=http://proxy2.yourcompany.com:1234

export https_proxy=$http_proxy
export HTTP_PROXY=$http_proxy
export HTTPS_PROXY=$http_proxy
export ftp_proxy=$http_proxy
export rsync_proxy=$http_proxy
export no_proxy="localhost,127.0.0.1,localaddress,.yourcompany.com,.local"

# Oracle, Java, other apps
export TNS_ADMIN="X:\Support"
PATH="$PATH:/c/ProgramData/Oracle/Java/javapath"
PATH="$PATH:/mingw32/bin:~/bin"
PATH="$PATH:/d/apps/gnuplot/bin"  
PATH="$PATH:/c/Program Files/Docker/Docker/Resources/bin"
PATH="$PATH:/c/Users/$USER/AppData/Roaming/npm"
PATH="$PATH:/c/Users/$USER/AppData/Roaming/cabal/bin"
PATH="$PATH:/c/Program Files/Amazon/AWSCLI"   # and so on...
export PATH

# git status on PS1 prompt
git_branch() {
     git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
export PS1="\[\e]0;\w\a\]\[\e[32m\]${HOSTNAME,,}:\[\e[33m\]\w\[\e[0m\]\[\033[35m\]\$(git_branch)\[\033[96m\]$\[\033[0m\] "
# old MSYS default:
#export PS1=\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[35m\]$MSYSTEM\[\e[0m\] \[\e[33m\]\w\[\e[0m\]\n\$

# more tweaks
LS_COLORS=$LS_COLORS:'di=0;37:' ; export LS_COLORS
alias az=autozip   #a handy script i keep in /opt/bin
alias vi=vim
alias ls='ls -p'
alias ll='ls -l'
alias lt='ls -lptr|tail'
alias my='cd "/h/My Documents"'
alias h=history
set -o vi
shopt -s checkwinsize
uname -a
cd $HOME
screenfetch -E

3. Add packages

Core packages

Now that MSYS2 can connect to the internet, we can get the latest cool packages. But first get the latest system updates (one-off)

$ pacman -Syu                                               

Hit [Enter] when prompted. Exit by closing the window, as instructed (don't use exit command).

Restart MSYS2 and get all the latest system updates with this command (should do this every week or so...)

$ pacman -Syu                                               

If one of the core packages was updated during script run you MUST restart MSYS2.

Build a great linux toolkit

The following covers all the tools you're likely to use, but there are many more packages available

$ pacman -S base base-devel net-utils git ruby wget man
$ pacman -S msys/openssh msys/vim msys/bc nano msys/tmux
$ pacman -S gzip zip unzip msys/p7zip tar msys/tree
$ pacman -S msys/winpty msys/ed msys/pwgen msys/zsh
$ pacman -S mingw64/mingw-w64-x86_64-jq
$ pacman -S msys/screenfetch

# choose ONE of these, based on your PC
$ pacman -S mingw-w64-i686-toolchain #32-bit
$ pacman -S mingw-w64-x86_64-toolchain #64-bit

# python tools
$ pacman -S mingw32/mingw-w64-i686-python3-numpy
$ pacman -S mingw32/mingw-w64-i686-python3-pip
$ pacman -S mingw32/mingw-w64-i686-python3-setuptools
$ pacman -S msys/python3-pip
$ curl https://bootstrap.pypa.io/ez_setup.py | python
$ easy_install pip
$ pip install grip
$ pip install awscli --upgrade --user

Example, searching for a new tool (do pacman -Ss to search for any unix tool you like)

$ pacman -Ss imagemagick
mingw32/mingw-w64-i686-imagemagick 7.0.1.10-1
    An image viewing/manipulation program (mingw-w64)       
mingw64/mingw-w64-x86_64-imagemagick 7.0.1.10-1
    An image viewing/manipulation program (mingw-w64) 

If you're on 32 bit windows (poor sucker), choose the "mingw32"/"i686" versions as per these examples:

$ pacman -S mingw32/mingw-w64-i686-imagemagick             
$ pacman -S mingw32/mingw-w64-i686-python2-jinja             

Note on GPG keys

While installing the above packages, pacman probably reported all sorts of warnings about gpg keys. These are used to authenticate the downloads. More info about setting up pacman's GPG validation:

Or, you can turn it off completely. Edit /etc/pacman.conf and uncomment the following line under [options]:

SigLevel = Never

This will result in no signature checking, and you will not need to set up a keyring with pacman-key.

4. Create RSA keys

This will save you from having to enter your password every time you log in to a remote server (via ssh, scp etc)

ssh-keygen

Only need to do this step once. Example: User baldrick, on a local computer named england

[baldrick@england]$ ssh-keygen -t rsa -b 2048

Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):  # Hit [Enter]
Enter passphrase (empty for no passphrase):               # Hit [Enter]
Enter same passphrase again:                              # Hit [Enter]
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.

ssh-copy-id

Copy your public key to remote server (ireland):

Do this for each server you connect to over ssh/scp etc.

[baldrick@england]$ ssh-copy-id baldrick@ireland

TROUBLESHOOTING If you get an error like this when running ssh-copy-id

/usr/bin/ssh-copy-id: ERROR: ssh_dispatch_run_fatal: Connection to 10.65.26.251 port 22: DH GEX group out of range

Add the following to file ~/.ssh/config :

KexAlgorithms diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1

Use scp/ssh more easily

Now you can scp / ssh to the remote host without password prompt!

[baldrick@england]$ scp baldrick@ireland:remote_log_file.txt .         # scp pull
[baldrick@england]$ scp -p ./local_data_file.txt baldrick@ireland:~    # scp push

[baldrick@england]$ ssh ireland
Last login: Wed Mar 30 17:10:43 2016 from 123.456.789.88

5. Customise mintty

Adjust the look and feel by clicking the "M" icon at the top of the mintty window, and selecting "Options..."

Disclaimer

This document is provided for information only, no guarantees. I have no association with MSYS2 or related projects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment