This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Lupus590's profile picture

How I Got Bash On Windows

Started by Lupus590, 14 January 2016 - 02:48 PM
Lupus590 #1
Posted 14 January 2016 - 03:48 PM
Thought I'd post this partly so I have a reminder but also because I though some of you may be interested. This 'tutorial' may expect some more technical knowledge than the CC ones that I have written already.

Disclaimer: Although I have had no problems with this on my Windows 10 machine, I will not be held liable for any problems that these programs cause to your computer.

Why this and not CygWin?
I don't like how CygWin did things, yes it may be nice to have a POSIX layer for things, but I didn't need that. My main complaint was the fact that my Windows drives were under some 'far away' directory structure, which I probably could have gotten use too. Instead I use Git-Bash, which mounts the Windows Drives directly under /.

Why this and not Linux?
Because I like my games which only run on windows, and that migrating OS/dual booting is an annoying task that I don't want to do.

Why this and not WSL?
Because i made this before Bash on Ubuntu on Windows (AKA WSL)was available to the public, and this has the advantage of being able to use native windows programs with ported *nix ones. I am trying out WSL though

What to download
Git - This provides bash but not all of the utilities that *nix users may be used to
GNUWin32 - Provides those missing utilities (the download may be hard to find)
ConEmu - Adds some useful features to any terminal, like copy and paste keyboard short-cuts.

install choclaty, it can download and install these for you: https://chocolatey.org/
After you have chocolatey installed you can run this and it will do everything else for you:
 choco install git gnuwin conemu 
you can skip to the first time run part if you like

To assist with tracking everything
So that you can have flexibility on where you install everything, I suggest that you write some things down. I will be defining some 'variables' so that I don't have to type out, "where you installed this thing" in my file paths.
Here is a list of the 'variables' i will be using, I advise that you have a piece of paper nearby to write down what values you are placing in these:
 --using lua style comments
UserPath --wherever your user directory is, should be /C/Users/UserName/ - get used to paths like this, this is how bash does it

--we will set these later, for know just know that they will be used
GitInstallPath
GNUWin32BatFilesPath
GNUWin32InstallPath
ConEmuInstallPath

Installing - read full instructions per program before 'executing'
We will start with GNUWin32 as it takes a while to download stuff. Run the program, it will make some bat files which we will run to do everything else. Set the GNUWin32BatFilesPath 'variable' to where it is placing these bat files. It should be quick, so when it's done open a command window (like it said). Do not use bash for this, it may give you issues when trying to run bat files. In cmd, navigate to GNUWin32BatFilesPath and run download.bat. This will take a while, so we will start the next step and return to this later. If you have to stop the download then use CTRL + C it will continue where it was if you run the bat file again.

While that downloads, lets install Git. Set the GitInstallPath 'variable' when you tell it where to install. When asked to select components, configure this as you please. If you are planning on using ConEmu then un-tick windows integration. (ConEmu provided this functionality).
As for path modification, I'm using the default "use git from git bash only", but you can do whichever you want. For line ending, again do what you want, I believe I'm using "checkout as-is, commit unix" but I use notepad++ as my default editor.
Git comes with a console, I haven't used it much and I don't think it matters if you use ConEmu. I choose MinTTY in the install though. I kept file system caching disabled as it is experimental.

Hopefully GNUWin32 is progressing smoothly. It may still be going though so let's install ConEmu. It may start by asking which version of the program to install (64-bit or 32-bit) I use the 64 bit version as I have a 64-bit Machine, if you want both then check the configure options, it can install both at the same time.

So GNUWin32 has downloaded everything (finally!), now to install it. Type (as prompted) "install C:\gnuwin32" and set C:\gnuwin32 as GNUWin32InstallPath in out 'variables'. And now we wait, again. You can do the stuff below while you wait though.


First time opening
ConEmu displays some configuration settings on first start up, set these as you want them. Make sure to change the startup task/shell to {Bash::Git bash} (it should find the correct one if git is installed, if not then I will show you how to change it later).

Configuration
Setting up ConEmu, under the X to close the window is an icon with 3 horizontal lines, left click it. Next click settings.
To get bash as the default shell: click on startup in the option tree. Under Specified named task, select {Bash::Git bash}
To get an option to open ConEmu with a right click, open the integration tab. and change {cmd} in the top command box to {Bash::Git bash} and click register. Ignore the bottom box.
Click save settings to close the settings window.

adding GNUWin32 to Git-Bash
in UserPath create a file called .bashrc and put this in it:
 #probably don't need some of these
export PATH=$PATH:"GNUWin32InstallPath/bin"
export PATH=$PATH:"GNUWin32InstallPath/sbin"
export PATH=$PATH:"GNUWin32InstallPath/lib"
export PATH=$PATH:"GNUWin32InstallPath/libexec"
export PATH=$PATH:"GNUWin32InstallPath/share"
export PATH=$PATH:"GNUWin32InstallPath/etc"
export PATH=$PATH:"GNUWin32InstallPath/doc"
export PATH=$PATH:"GNUWin32InstallPath/include"
Note: anything is this file will be executed each time you open bash. Additionally, bash may complain about a missing file when you next open it, it should create this file for you.

Don't forget to check on GNUWin32
Just press enter, the default options are fine. Now it has to check that all the documentation is in the right place. (Yes, lots of waiting. this is the last one.)

Package Manager
If you want a package manager like program then you may want to check out Chocolatey. I have it but haven't used it. I've heard that it's quite good.

Just started using it on a fresh Windows 10 install, IT'S AMAZING!

EVERYTHING TO DO THIS SSH IS BROKEN AT THE MOMENT
You can ssh to windows 10 which will give you a cmd shell , Microsoft added that at some point.

SSH-Agent - Useful for GitHub
If you use GitHub and what to use it via the command line then you will want to follow these instructions: https://help.github....-the-ssh-agent/
After you do you wont have to type your username and password again (just make sure that origin is this format: [email protected]<script data-cfhash='f9e31' type="text/javascript">/* */</script>:UserNameOrOrganisation/Repo.git )

Setting up SSHD (SSH Server)
Open bash and run ssh-keygen, it will ask where to save some files (and suggest a location, just press return/enter to use the default), write this down as KeyPath 'variable'. It will ask if you want a passphrase, I'm not sure what this does so I left it blank. Edit: I believe its a password to lock/encrypt the keys.

Navigate to GitInstallPath/etc/ssh and open sshd_config in your preferred plan text editor. Find the line where it says UsePrivilegeSeparation (line 110) and change it to no. If you can't save over the existing file then save in another place and move it back.

We will need a bash script to start the sshd. The file name is not important, and for now, make it on you desktop. Open the file in your preferred plain text editor and copy-paste the following:
#! /bin/bash
/usr/bin/sshd -h KeyPath

Make sure that the file has the .sh extension (show extentions), rename it if it doesn't. Also, make sure that bash is configured to be the default for .sh files. Move this file to the startup folder in the start menu (C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp).

You can now SSH into your windows machine like you would on *nix. When it asks for your password, it wants the one you use to log into windows (of the account on the machine that you are connecting to).
Edited on 05 October 2016 - 07:05 PM
SquidDev #2
Posted 14 January 2016 - 06:56 PM
Interesting. My setup uses MinGW/MYSYS instead of GNUWin32. I'm pretty sure this is what powers Git for Windows, so I guess you save some space that way. I hadn't seen ConEmu though - looks like it may be a nicer alternative to the asic bash/cmd shell.
Lupus590 #3
Posted 08 February 2016 - 09:22 PM
OP edit: some corrections on setting up the SSH server
cmdpwnd #4
Posted 26 March 2016 - 11:43 PM
how would you install external packages? is it dpkg/yum like or only pure gnu? I love the idea but i don't see the flexibility in comparison to a standard distro?
Lupus590 #5
Posted 26 March 2016 - 11:54 PM
You could compile the open source ones yourself (prepare for a lot of porting).
You may also be interested in choco.

Otherwise what I've shown in the OP is the best I can do.
Edited on 26 March 2016 - 10:54 PM
Lupus590 #6
Posted 08 April 2016 - 07:47 PM
OP update: add section on ssh-agent and choco
Edited on 08 April 2016 - 05:50 PM
H4X0RZ #7
Posted 08 April 2016 - 09:18 PM
There's bash for windows 10 now :D/>
LDDestroier #8
Posted 11 April 2016 - 02:46 AM
There's bash for windows 10 now :D/>

PM me once Windows becomes free and open-source.
cmdpwnd #9
Posted 11 April 2016 - 11:54 PM

Win 10 integrated bash via Ubuntu under WSL
FUNCTION MAN! #10
Posted 15 April 2016 - 01:45 AM

Not the point. He meant that Windowze isn't FLOSS, which it isn't.

It's just awful.
Lupus590 #11
Posted 23 June 2016 - 09:14 PM
OP Edit: chocolatey is amazing! added instructions for installing with chocolatey