Newer
Older
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# Cygwin setup on *Windows*
[Cygwin](https://www.cygwin.com) is a Unix-Emulator that provides
a terminal in which Unix commands can be executed on Windows
using
[bash](https://en.wikipedia.org/wiki/Bash_(Unix_shell))
(*Bourne Again Shell*) as command-line interpreter -
*bash* was developed in 1989 as a successor to the
*Bourne Shell:*
*[sh](https://en.wikipedia.org/wiki/Bourne_shell)*.
[<bash terminal>](https://cdn.ttgtmedia.com/rms/onlineimages/REF_bash_command_line_3.jpg)
*Cygwin* is <span style="text-decoration:underline">not</span>
a Unix container or virtual machine system (unlike
[WSL](https://learn.microsoft.com/en-us/windows/wsl/about)).
*Cygwin* emulates most (not all) Unix system calls such that
most Unix commands can execute on Windows.
Alternatives to *Cygwin* such as
[GitBash]()
can be used, but have some flaws and drawbacks on Windows
(*GitBash*, for example, performs strange path conversions, see
[link](https://stackoverflow.com/questions/54258996/git-bash-string-parameter-with-at-start-is-being-expanded-to-a-file-path)).
Good introductions to *bash* are:
- [https://cs.lmu.edu/~ray/notes/bash](https://cs.lmu.edu/~ray/notes/bash).
- Also recommended is the
[Tutorial for Beginners](https://linuxconfig.org/bash-scripting-tutorial-for-beginners).
## Steps
1. [Installation](#1-installation)
2. [Configure paths in .bashrc](#2-configure-paths-in-bashrc)
## 1. Installation
1. Download the installer `setup-x86_64.exe` from
[https://www.cygwin.com/install.html](https://www.cygwin.com/install.html).
1. Run the installer `setup-x86_64.exe`.
- select useful Unix commands during installation:
- Editors/`vim` - visual editor,
- Web/`wget` - web downloader,
- Net/`curl` - web downloader.
1. Change *cygwin* default path `/cygdrive/c` to: `/c`:
- navigate to the *cygwin* installation directory.
- inside, edit `/etc/fstab` and replace line
```
none /cygdrive cygdrive binary,posix=0,user 0 0
with:
none / cygdrive binary,posix=0,user 0 0
```
1. Add bash-user that works with Windows and create
*bash* HOME directory.
- Find out your Windows user name: <user_name>
- Create or select a directory that you want to use as
HOME-directory for *bash*, e.g. your Windows
HOME-directory `C:\Users\<user_name>`.
- Edit file `/etc/nsswitch.conf`:
- to use Windows HOME-directory, comment line
```
#db_home:
```
- for using a new directory as HOME-directory, enter
```
db_home: /cygdrive/c/<path>
```
1. Open a new *bash* terminal and test changes:
```sh
$ whoami
<user_name> # your user name appears
$ echo $HOME # print path to HOME-directory
<home_directory> # output, e.g. /c/Users/svgr
$ cd $HOME # change into HOME-directory
$ ls -la # show content
total 203
drwxr-xr-x+ 1 svgr2 Kein 0 Oct 4 22:20 .
drwxrwx---+ 1 svgr2 Kein 0 Jan 1 2022 ..
-rw------- 1 svgr2 Kein 14476 Oct 4 22:20 .bash_history
-rwxr-xr-x+ 1 svgr2 Kein 2717 Oct 4 20:28 .bashrc
...
$ echo Hello >hello.txt # create file hello.txt with content Hello
$ ls -la # show new file exists in $HOME
total 203
-rw-r--r-- 1 svgr2 Kein 6 Oct 7 23:38 hello.txt
...
$ cat hello.txt # output content of file
Hello
```
1. Open Windows file explorer (
[ ? ](https://geekflare.com/wp-content/uploads/2021/06/14-alternative-file-managers-to-replace-windows-10-file-explorer.jpg)
) and navigate to file `hello.txt`.
Open the file by clicking (ending `.txt` should open the
file with *notepad*).
1. Return to *bash* terminal:
- change to HOME-directory and
- open file `.bashrc`
```sh
$ cd # change to bash HOME-directory
$ ls -la # find file .bashrc
total 203
-rwxr-xr-x+ 1 svgr2 Kein 2717 Oct 4 20:28 .bashrc
$ cat .bashrc # output file .bashrc
...
```
## 2. Configure paths in `.bashrc`
[PATH](https://en.wikipedia.org/wiki/PATH_(variable)) is an
environment variable on Unix-like operating systems that
specifys a set of directories where executable programs are
located. A *"command not found"* error occurs when PATH is
not properly configured.
1. Open `.bashrc` using an editor, e.g. *vim* and append PATH
configurations.
```sh
$ vim .bashrc # open .bashrc in vim editor
```
1. Append PATH configurations at the end of the file - only
those relevant on your system - and djust paths for your
system:
```sh
# add Windows system paths
export PATH=".:/usr/bin:/usr/local/bin"
export PATH="${PATH}:$(cygpath ${SYSTEMROOT}):$(cygpath ${SYSTEMROOT})/system32"
# add Java path
export JAVA_HOME="/c/Program Files/Java/jdk-21"
export PATH="${PATH}:${JAVA_HOME}/bin"
# add Python path
export PYTHON_HOME="/c/Users/svgr2/AppData/Local/Programs/Python/Python312"
export PATH="${PATH}:${PYTHON_HOME}"
export PATH="${PATH}:${PYTHON_HOME}/Scripts"
# add Docker path
export DOCKER_HOME="/c/Program Files/Docker/Docker"
export PATH="${PATH}:${DOCKER_HOME}/resources/bin"
...
```
1. Verify paths have been added to *PATH* variable:
```sh
$ source .bashrc # reload .bashrc to activate chances
$ echo $PATH # show PATH
.:/usr/bin:/usr/local/bin:/c/WINDOWS:/c/WINDOWS/system32:/c/Program ...
$ echo $PATH | tr ':' '\n' # pretty print PATH
.
/usr/bin
/usr/local/bin
/c/WINDOWS
/c/WINDOWS/system32
/c/Program Files/Java/jdk-21/bin
/c/opt/maven/bin
/c/Users/svgr2/AppData/Local/Programs/Python/Python312
/c/Users/svgr2/AppData/Local/Programs/Python/Python312/Scripts
/c/Program Files/Docker/Docker/resources/bin
/c/Program Files/MySQL/MySQL Workbench 8.0 CE
/c/Program Files (x86)/Git/bin
/c/Program Files/Oracle/VirtualBox
/c/opt/Qt6/Tools/mingw1120_64/bin
/c/opt/Qt6/6.2.4/mingw_64/bin
```
Paths may vary based on your system.
1. Start programs to verify paths have properly been set.
```sh
$ java --version
java 21 2023-09-19 LTS
Java(TM) SE Runtime Environment (build 21+35-LTS-2513)
Java HotSpot(TM) 64-Bit Server VM (build 21+35-LTS-2513, mixed mode, sharing)
$ python --version
Python 3.12.0
$ docker --version
Docker version 24.0.6, build ed223bc
```