Skip to content

Commit 295979c

Browse files
committed
appendix, setup for windows
1 parent e56277c commit 295979c

File tree

3 files changed

+222
-0
lines changed

3 files changed

+222
-0
lines changed

appendix/Makefile

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.PHONY = pdf
2+
3+
pdf:
4+
asciidoctor-pdf -o SETUP_WINDOWS.pdf SETUP_WINDOWS.adoc

appendix/SETUP_WINDOWS.adoc

+218
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
= Setup your environment on a Windows 10 machine
2+
3+
This tutorial draws heavily from https://github.com/michaeltreat/Windows-Subsystem-For-Linux-Setup-Guide[this terrific guide by Michael Treat].
4+
5+
== Installation of WSL
6+
7+
For this setup you need a Windows 10 machine, with all updates done.
8+
9+
=== Enable WSL Feature in Windows.
10+
11+
First we need to enable WSL in Windows.
12+
13+
* Right click on the start menu and click on Settings.
14+
* In the Search box, type Turn Windows Features On Or Off and click on the item that populates in the list.
15+
* A window will pop up with a list of folders with checkboxes next to them. Scroll down and check the box for Windows Subsystem for Linux.
16+
17+
This will install the needed files. Follow any directions that pop up and restart your computer when asked.
18+
19+
=== Install the Ubuntu app from the Windows Store.
20+
21+
* Go to Microsoft store and install the Ubuntu App
22+
* Follow the on-screen prompts to install the app.
23+
* When the app is ready, the button that said 'Install' will change to say 'Launch'. Click Launch. This will start the Ubuntu installation. This installation only happens the first time the app is launched. It's the actual Ubuntu (or Linux) OS installing and mounting to your Windows FS.
24+
25+
WARNING: Anytime you uninstall the app and reinstall it you will lose any data that lives on the Linux Filesystem. This inlcudes databases, configs, `.profile`'s, and anything else you might have stored on the NON-Windows Filesystem. Make sure to back this data up!
26+
27+
=== Finish Installing the Ubuntu App.
28+
29+
Then we need to setup your user name and password for Ubuntu.
30+
31+
* It will ask you to enter a username. This will be the root / admin user for the Ubuntu FS. Don't use capital letters in this name.
32+
33+
* It will then ask you to enter and confirm a password. Also note that it will protect your password by not displaying it to the screen when you type, but it is registering your key strokes.
34+
35+
NOTE: Security is important at all levels, so even though you have to use this password often, don't be tempted to make it too simple (as I suggessted in an earlier version). Essentially all of your Window's files can be viewed and modified by this user, so keep that password safe and strong.
36+
37+
Finally, the prompt will change and you will be on a command line. Type pwd to see where you currently are on your machine, you should be at `/home/<your username>`. This is the root level of your Ubuntu user.
38+
39+
=== Updating the `.profile` file
40+
41+
In order to change how your terminal looks, we need to add some code to a file that lives in your Ubuntu user's root directory.
42+
43+
. Open the Ubuntu app and type `ls -a`. You should see a `.profile` file there. If not, then type `sudo touch .profile`.
44+
. Type `sudo nano .profile`. This will open the file in the command line editor Nano.
45+
. Copy and paste this code into the editor. You can paste with right-click:
46+
47+
----
48+
# This allows you to switch between the Ubuntu root and your Windows Root.
49+
# wr evaluates to the absolute path to your Windows user's root.
50+
export wr=~/../../mnt/c/Users/<Windows Username>/
51+
52+
# This gives us a quick way of moving directly to the Windows root
53+
alias cdwr='cd "$wr"'
54+
55+
# This brings you to your Windows Working directory immediatly when you open a new terminal.
56+
cdwr
57+
----
58+
59+
After pasting that in, you will need to add your Windows username right after `/Users/`, e.g., `/Users/MyName/`.
60+
61+
If your path has a space, you can use an backslash escape character to include the space, e.g., `/Users/My\ Name/`.
62+
63+
After that you're done in this editor, so press `Ctrl-x` at the same time to quit. It will ask if you want to save changes. Hit `y` and the editor will save your changes. It will then ask what to name the file. Just hit enter to keep the same name.
64+
65+
Close the Ubuntu app and open it to enable your changes.
66+
67+
### Extra Info
68+
69+
In the file you pasted there was a section at the bottom that exports `wr` and sets up the `cdwr` alias.
70+
This add the variable `$wr` to your environment.
71+
If you want to use a relative path, but don't want to go all the way up to the Ubuntu FS and then work down to the Windows FS, you can use the `$wr` variable as a shortcut to the Windows root instead, e.g.:
72+
73+
----
74+
cd $wr/about_me/scripts
75+
----
76+
77+
Instead of:
78+
79+
----
80+
cd ~/../../mnt/c/Users/MTreat/Development/about_me/scripts
81+
----
82+
83+
This also works with tab completion as well, which is awesome.
84+
85+
- `cdwr`
86+
87+
Now when you type `cdwr` it will bring you to the root of your Windows User! This makes navigating between the two file systems super easy.
88+
89+
* To navigate to the Ubuntu root, you will type the normal `cd ~`.
90+
* To navigate to the Windows Root, you will type `cdwr` with NO space!
91+
92+
If you decide to add a directory to your Windows User's root to hold all of your work, e.g., `/Users/MichaelLeonTreat/Development`, you can come back to this file and update the `export wr` line so that it moves directly into that directory. Just add the name of the directory to the end of the path after your username.
93+
94+
In case you ever need it, the Ubuntu FS lives on your Windows FS on the path that looks very similar to this:
95+
96+
`C:\Users\<user>\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs`
97+
98+
If you want to create your own custom command line prompt you can check out http://bashrcgenerator.com or http://ezprompt.net and use the code that provides instead of the code here.
99+
100+
== Install Git
101+
102+
Git is a version control system that allows you to track your projects' changes over time, and allows for an extremely collaborative process to exist.
103+
104+
. Visit https://git-scm.com/ to download and install Git.
105+
. Follow the onscreen instructions.
106+
- Choose the default values for each prompt
107+
. Continue choosing the default options to finish the installation.
108+
109+
NOTE: Git for Windows also comes with a terminal called Git Bash. This is what a lot of Windows users have used in the past as their solution to the POSIX / Unix-like terminal problem. We will be using the Ubuntu app instead.
110+
111+
=== Verifying Git
112+
113+
Now that we have Git installed on both of the file systems, lets check which Git Ubuntu is using.
114+
115+
. Open a new terminal (the Ubuntu App) and type `whereis git`. This will show you all the places git is on your computer.
116+
. Now type `which git`. This will show you which git is executed when you type `git`. Notice that it only shows the one in Ubuntu - that is the git that will be used when you are in your terminals.
117+
118+
=== Set the Git Config
119+
120+
Create an account on https://github.com/[GitHub].
121+
122+
Then add your email and name to the Git config. This will allow you to commit and push things to GitHub. Make sure to include the space after `.email` and `.name`, and always remember to close your quotes ' ' and " ".
123+
124+
. Type `git config --global user.email 'your email here in single quotes'`.
125+
. Type `git config --global user.name 'Your Name In Single Quotes'`.
126+
127+
Once you are done, type `git config -l` and verify that it has your name and email saved correctly.
128+
129+
=== Set up SSH Keys
130+
131+
SSH stands for "secure shell" and is a protocol for encrypting communications with remote systems.
132+
You will need an SSH key pair which can be found in two text files that contain your "public" and "private" keys.
133+
We will add your public key to your GitHub settings so that you can securely communicate with the GitHub.com server without having to authenticate with a username and password.
134+
135+
* Open a terminal
136+
* Execute `ls ~/.ssh`
137+
* If you see `No such file or directory`, then execute `ssh-keygen`, hit `Enter` to accept all defaults
138+
* You should have two files at least like `id_rsa` and `id_rsa.pub` which represent an SSH key pair. The `.pub` file contains the _public_ key which you need to copy to GitHub. The other file is your _private_ key that you should never touch, copy, use, or email. If that key is compromised, you should delete the files and use `ssh-keygen` to generate a new pair. You can generate as many pairs as you like, saving them into different files.
139+
* Copy the contents of `~/.ssh/id_rsa.pub`. Otherwise, you can use `cat ~/.ssh/id_rsa.pub` to "concatenate" the contents to the screen, then copy the text to your clipboard.
140+
* On GitHub.com, go to your user settings by clicking on your name/icon in the upper-right corner to view a drop-down list. Click on "Settings" (2nd from the bottom of the list).
141+
* In the left side, there is a table. Click on "SSH and GPG keys".
142+
* Click on the big green "New SSH Key".
143+
* Give your key a name like "laptop" and paste in the _public_ key value.
144+
* Click the big green "Add SSH key" button.
145+
146+
=== Forking the repo
147+
148+
* Go to https://github.com/kyclark/tiny_python_projects
149+
* Click on the "Fork" button in the upper-right of the page, just below the big black bar.
150+
* Fork into _your_ repository.
151+
* Verify that you have something like https://github.com/id/tiny_python_projects where `<id>` is _your GitHub username_.
152+
* Go to the page of the repo and clone the repo on your computer using the command git clone `<ssh_clone>`
153+
154+
NOTE: If you get a permission error, try to run this:
155+
156+
----
157+
$ cd
158+
$ sudo umount /mnt/c
159+
$ sudo mount -t drvfs C: /mnt/c -o metadata
160+
----
161+
162+
Then go back to the Windows subsystem (cdwr command) and try to clone again.
163+
164+
=== Set an upstream repository to get updates
165+
166+
In order to get updates from my GitHub copy of the repo, you must set it as an "upstream" repository.
167+
168+
Change into your local repo checkout, e.g.,
169+
170+
----
171+
$ cd /tiny_python_projects
172+
$ git remote add upstream https://github.com/kyclark/tiny_python_projectw.git
173+
----
174+
175+
== Install Python
176+
177+
To install python run the following at the WSL:
178+
179+
----
180+
$ sudo apt update && upgrade
181+
$ sudo apt install python3 python3-pip ipython3
182+
----
183+
184+
== Install PyCharm
185+
186+
NOTE: you can only use and invoke PyCharm for the files in the Windows filesystem (also accessible form the WSL at /mnt/c/Users/<user-name>).
187+
188+
PyCharm is a complete IDE for Python, allowing you to run directly the code through the interface. It has a lot of options and possibilities, but is more difficult to use. Alternatively, you can install Notepadd++, which is a good old notepad, that will allow you to edit your code (see below).
189+
190+
* Download the community edition and install https://www.jetbrains.com/pycharm/download/#section=windows[PyCharm].
191+
* In order to enable interactive coding you should also have python installed in Windows. Go to the Microsoft store and install the latest Python.
192+
* For each project you create you'll have to add the python interpreter properlt for PyCharm to run. If you have issues with the interpreter, see this https://www.jetbrains.com/help/pycharm/configuring-python-interpreter.html[help page].
193+
194+
== Create the alias to launch PyCharm from WSL
195+
196+
. Open a new terminal (the Ubuntu App) and type `whereis git`. This will show you all the places Git is on your computer.
197+
198+
. Open your bash configuration:
199+
200+
$ nano ~/.bashrc
201+
202+
. Add to the end of the file:
203+
204+
$ alias charm="/mnt/c/Users/<user-name>/AppData/Local/JetBrains/Toolbox/apps/PyCharm-P/ch-0/<version>/bin/pycharm64.exe"
205+
206+
. You're done in this editor, so press `Ctrl-x` at the same time to quit. It will ask if you want to save changes. Hit `y` and the editor will save your changes. It will then ask what to name the file. Just hit enter to keep the same name.
207+
208+
. Update your bash profile:
209+
210+
$ source ~/.bashrc
211+
212+
Now you can use `charm .` & to open PyCharm projects from WSL.
213+
214+
=== Install Notepad++
215+
216+
To download and install Notepad, go to the https://notepad-plus-plus.org/[download page]. And follow the instruction.
217+
218+
You're done! Good job!

appendix/SETUP_WINDOWS.pdf

128 KB
Binary file not shown.

0 commit comments

Comments
 (0)