I recently set up an Ubuntu home server, mostly to do development work on, as well as to back up some files. In fact I’m writing this post on the home server right now, via LazyVim, since I just like writing everything from the terminal.
The biggest reason for me to set it up was because of how little storage I had on my personal MacBook Pro. I have the 2019 model, which has 120GB of storage of 8GB RAM. To be honest it almost feels criminal for Apple to even be able to release a computer with storage this little; not to mention that the required software is I think almost 30GB combined. Which is why I think the minimum storage for Macs now is 200GB, at least from what I saw on the online store. It was getting super annoying to worry about cleaning up files whenever I wanted to start a new project, but my research told me that adding storage was not a simple procedure.
It was also annoying when, for the longest time I had a very old MacOS running (I want to say Catalina or Big Sur…), and I was starting to face compatibility issues when installing new software for projects. At a certain point I couldn’t even run homebrew because it was no longer supported on my OS, stuff like that… But then the issue was, if I wanted to upgrade my OS, I would have to download the Installer, and that was like 30GB, so I’d have to make space on my computer for that. Deleting old images, rummaging through disorganized clutter to find anything worth removing…
So needless to say I didn’t want to have to do that anymore. Luckily I had an old Lenovo Thinkpad that I got from my dad (which I used to use to try learning how to setup and use different Linux distros as a personal laptop), and I realized I could just use it as a server.
Setting up
Install
For the basic installation process, I just followed this YouTube video.
I’ve installed Linux on computers before, so booting from USB and setting things up were not too foreign. Although I do always have to lookup the exact commands on Mac for how to burn the ISO onto the USB, and then how to undo that and recreate a filesystem on the USB, so maybe that’ll be a good thing to do a write-up on later.
Setting up
So once the OS installation was done, next was to setup the software I needed for my daily workflow. I have my dotfiles saved in a git repository (private ATM). I then used the bash script below to install the software I need, and to add symlink to the dotfiles from where they are needed (Under ~/.config/, for example):
https://gist.github.com/mitchshiotani/7ccfdb82801ac2fbf4df7d2858aef004
Just a few comments on what the script is doing:
GNU Stow
The script first installs GNU Stow, which is a very useful tool to help create symlinks to config files from where they are needed.
The basic gist of this tool is that you don’t have to manually create the symlinks; Stow does that for you, and even handles cases with complex directory structures.
I learned about Stow from the Primeagen, so hopefully this video gets you excited about using it, like it did for me. I feel like a lot of what I do with this home server is trying out new things I learn on YouTube, so I guess this was naturally just one of them.
Fish
I use the fish shell. A lot of people hate it because it’s not POSIX compliant, so if you were to copy and paste commands from the internet to your shell and execute them, they won’t work, but I just switch to bash/zsh when that’s what I want to do.
Fish is pretty nice because it does a lot of things for you automatically. Fuzzy-matching directory and file names when you hit tab is huge. I really like the command suggestion as well; it’s more convenient than bash/zsh where you would manually reverse search commands. It also does small helpful things like showing a list of available command arguments when you hit tab, and showing git info via the prompt.
So I recommend anyone who wants to become a more terminal-heavy user to consider using fish shell! It’s a lot of good stuff without all the config hassle.
Other software I use
Tmux is a huge daily driver for me. Might write a bit more on it in another post!
Let’s see, what else. In the last line of the shell script, I install a bunch of Modern Unix packages, which are very useful. Especially ripgrep, fd for searching filenames and words. And I use dust a lot to check for heavy files. I use btm a lot to keep track of system resources as well.
So that was pretty much it for the meat of what I had to do to setup.
Troubleshooting
Of course setting up didn’t come without its issues.
One of the main issues I had was regarding copying to my machine’s local clipboard when using tmux’s copy mode. I was ultimately able to get it working with the configuration below:
## ~/.tmux.conf ##
set -g set-clipboard on
# vi mode
# also refer to: https://blog.sanctum.geek.nz/vi-mode-in-tmux/
set-window-option -g mode-keys vi
bind-key -T copy-mode-vi 'v' send -X begin-selection
bind-key -T copy-mode-vi 'y' send -X copy-selection-and-cancel
# needed to use local clipboard via ssh
# (https://github.com/tmux/tmux/wiki/Clipboard)
set -as terminal-features ',screen-256color:clipboard'
The last setting, set -as terminal-features ',screen-256color:clipboard', being the most important.
To be honest, I still don’t really remember how it works. I think if you have tmux version higher than 3.2, and one of the major terminal emulators, the config above should just work. I used to use iTerm2, where I think I didn’t even have to do this for everything to work, but since moving to kitty, I’ve bumped into issues like this a little more.
What else… I think that’s pretty much it. I’ve still got to work on a few things regarding tmux (my cursor won’t change shape in LunarVim when I’m in insert mode, for example), but nothing major.
Enabling remote access
So I set up a local server, which is great, but I didn’t want to be limited to only using it when I was at home, on my local network that it was accessible through. If possible I wanted to be able to access it from anywhere.
Thankfully, it was possible via ngrok. I had used ngrok before to allow remote access to a web app that was running locally on my computer, but upon further research I realized it was possible to allow remote access of TCP connections in general, including SSH.Check out the docs on how to do it:
You need to register a credit card number to set up the endpoint, but actually using it is free. Latency doesn’t seem bad at all; in fact I’m connected remotely right now as I’m writing this on the server, and it’s quite smooth.
Well, that’s about it. Overall, it was nice that I was able to automate a lot of the setup, and the things I felt would cost me money, like setting up remote access, were actually free. So now I have a powerful 8GB RAM, 500GB storage machine at my disposal wherever I am.
So if you’ve always wanted to have a remote server, but you’re scared of using Cloud services and are worried about those fluctuating charges you have to pay in US Dollars (I guess I’m extra sensitive to that since I’m in Japan with the weaker yen…), consider this alternative!