Learn and Use Linux for Programming

This is just my opinion, but I think it’s important and gets missed all the time. I would urge students to use Linux to learn Julia and indeed, for any and all programming. Windows is the dominant OS in the world and it’s a great operating system for the average citizen - but there is so much that is walled off from you. If you’re learning to program and don’t know how to use Linux, your commitment to Windows will add unnecessary complexities that don’t exist in Linux. Linux has a seamless interaction between its terminal and its file system - there is nothing that is unavailable to you. If you’re learning Julia by using its REPL, your OS won’t matter much. But when you come out of the REPL and start running .jl files line by line and interacting with your computer’s backend, you don’t want a proprietary OS interfering with this process.

Give Linux a try - WSL is an excellent intro, but even better - buy a used laptop on ebay and install an actual Linux distro on it - it’s fun. Learn to navigate its file system and use its terminal - you’ll ramp up quickly and you may never look back.

10 Likes

Would recommend Pop!_OS https://pop.system76.com/

8 Likes

The UNIX Philsophy

To those who are starting on their Unix/Linux journey, the first book I recommend is The UNIX Philosophy by Mike Gancarz. It’s a small book that can be read in a day or two, and it explains why Unix behaves the way it does. It also explains how one can play to its strengths which may not be obvious to someone coming from a different OS.

Tenets

  • Small is beautiful.
  • Make each program do one thing well.
  • Build a prototype as soon as possible.
  • Choose portability over efficiency.
  • Store data in flat text files.
  • Use software leverage to your advantage.
  • Use shell scripts to increase leverage and portability.
  • Avoid captive user interfaces.
  • Make every program a filter.

These aren’t hard immutable rules, but they’re good guidelines for getting the most out of a Unix/Linux system.

Addendum

  • He’s written an updated version of this book called Linux and the Unix Philosophy, but I haven’t read it.
  • This book has become more expensive than I remember. Hopefully, you have access to a library that has this book. My old university’s library is where I first found it.
  • As an owner of a used laptop from eBay, I would temper your expectations when it comes to running Julia on it. Due to all the compilation Julia does, it can be painfully slow on an older computer.
7 Likes

Can’t wait for their new COSMIC DE!

I definitely want to read this book. The suggestion for buying a $50 laptop is for those who have never tried Linux - an inexpensive test box can reduce the fear of taking on the install of Linux on an actual physical machine. But a good point about resource-heavy computation in Julia. I recently picked up a T470s ThinkPad for $130 with an i7 processor and put Arch on it - it’s fast.

2 Likes

That’s a good deal, and a machine with T470-tier performance is good enough for doing Julia work. I have a ThinkPad too, but it’s an older X220, and compilation time is an issue. On the bright side, the X220 is near indestructible and has outlasted 2 newer laptops.

(I do most of my Julia coding on a faster desktop.)

Could you provide some easy-to-digest and common examples of such interference? I’ve never used Linux let alone know OS differences.

Incidentally, another Julia-specific reason to use Linux, even via WSL, is that StaticCompiler.jl does not have Windows support. I haven’t heard of other libraries restricted to fewer OSs than base Julia.

1 Like

(This is my little Christmas present for whomever finds it useful.)

Start Pluto at Boot Time for Linux/Unix

Here is a little hack I came up with that starts Pluto automatically when my computer boots. It works by using shell scripting, tmux, and the @reboot feature of cron. Let’s start with the shell script which I call tmux-pluto.

tmux-pluto

#!/usr/bin/env bash
tmux has-session -t pluto 2> /dev/null && {
  echo "A tmux pluto session already exists."
  exit 1
}
tmux new-session -ds pluto -c "$HOME/.julia/pluto_notebooks" -n julia
tmux send-keys "julia" Enter
tmux send-keys "using Pluto" Enter
tmux send-keys "Pluto.run(launch_browser=false)" Enter

The tmux-pluto script starts a tmux session named “pluto”, and it sends keys to tmux to start up a Julia REPL and then start Pluto. It also has a guard in the beginning of the script so that it won’t start more than one tmux session named “pluto”.

You could just run this script from the command line, but I run it from cron such that it runs at boot time. Run crontab -e and add the following line.

# Run tmux-pluto at boot time.
@reboot tmux-pluto

Troubleshooting

  • (Obviously), make sure you’ve already installed Pluto beforehand.
  • Make sure tmux-pluto is in your PATH and is executable.
  • Note that cron’s PATH is often not the same as the PATH you have in your interactive shell session, and you may have to configure PATH in your crontab too.
  • To get access to the REPL session that’s running Pluto, run this in your shell: tmux a -t pluto
    • Ctrl-c here will stop Pluto.
    • Ctrl-b d will get you out of tmux.
    • See tmuxcheatsheet for more hints.

Play with it.

If everything worked, Pluto should be waiting for you at:

http://localhost:1234/

If you use Pluto a lot, this might be useful to you. Also feel free to make changes to suit your workflow. For example, if you keep your notebooks somewhere other than $HOME/.julia/pluto_notebooks, go ahead and change the tmux-pluto script to match your system.

Could this be done in Windows?

Maybe, but the culture of automation is very strong in the Unix world, and making little time savers like this is commonplace. There’s less of this automation mindset in the Windows world.

5 Likes

Quite honestly, I agree with you. All the Top500 HPC systems run Linux.
However I would put my 2 cents worth in as somene with experience in industry. Engineers are often issued with Windows laptops whi
ch authenticate using Active Directory. You typically dont get a choice in this.
My favourite utility is MobaXterm. Also have introduced Altair Access in a couple of places and it is popular with engineers.

1 Like

I’m a retired engineering tech, not a professional programmer or software engineer, so I’m no authority. I’ve used Linux for 12 years - I like using the terminal and being able to access anything and everything on my system. I use Windows as well for daily surfing and streaming. When I began studying the C language, on Linux I could write a .c program and compile it with gcc right from the terminal. To run C at all on Windows, you need to set up the path and environment and use Cygwin or Msys2 and it just adds abstraction and complexity.
I once posted on reddit asking the professional devs what they use - Windows or Linux? I was just curious. The post got hundreds of responses - most pros agreed that they preferred Linux if given the choice, but many were issued Windows like yourself, and found a way that worked for them. Many on the forum attacked me, picking up on my Linux bias and called me a Linux snob, but that’s reddit for you.
I’m an advocate for Linux and open-source - for sharing knowledge, as we do here on this forum. This post here was meant for students and those who would like to understand their computer inside and out. No professional needs to bother to listen to my advice. Windows is great, but it’s a proprietary OS and Microsoft is never going to give the user access to everything - even on their own computer. Thanks for the reply - I’m checking out MobaXterm today.

The standard compiler choice would be MS Visual Studio. Windows itself is written in C and C++. Cygwin and Msys are useful if you need a Unix compatibility layer, e.g. if you use GNU Make as the build system.

I like both Linux and Julia, but they are rather orthogonal tools. Julia does not subscribe to the Unix philosophy, and Julia is not a typical Linux program in terms of distribution channels (one binary tarball for all distros, rather than individual distro package managers).

3 Likes

There’s no particular obstacle that I can point to with Julia - I’m too new to it, and to programming in general. You can certainly use Windows to learn it, with or without WSL. I’ve just become used to having full access - from the high level languages on top right down to the bare metal - all from that terminal - it is after all, YOUR machine. Windows does not allow that - it prevents you from accessing a lot of the system - admittedly, to protect the average user from borking their OS. It’s hard to explain the freedom and power that Linux gives you without actually using it. Maybe the best way to put it is that if you have trouble doing something - say using Julia’s Plots package or the one you mentioned - maybe the backend isn’t responding. If it’s a Linux OS issue, you can learn a way around it - the OS itself won’t prevent you. I was talking with Dave Cohen on youtube’s Tutorial Linux channel about the infamous Linux command you can type in the terminal that will permanently wipe out your operating system in 5 seconds (I won’t print the command here) - THAT is giving the user power over their computer.

1 Like

I’ve heard a lot about this distro and I have a spare laptop - time to try it out!

I’m studying programming languages more or less as an academic. It’s just my preference to always use the Linux terminal and NOT use an IDE for programming. Of course, that approach wouldn’t make sense for a professional developing an actual project comprised of many files and directories.

As long as you don’t have to debug. :slight_smile:

Maybe Debugger.jl? Have yet to try it.

Infiltrator.jl – it is worth its (figurative) weight in gold!

I’m not worthy.

@greatpet - "Julia does not subscribe to the Unix philosophy . . . "

When you wrote this in your reply to my post last week, I didn’t quite see the relevance. Now I’m starting to get what you mean - packages, modules, multiple dispatch, etc. - Julia’s a great language, but I think I’m more of a Linux and low-level language guy. Not being a true programmer, I’m learning just to learn - with high-level languages like this there’s just too much abstraction from what’s underneath and I miss that from having spent so much time with the C language - for all its flaws, at least you can see what it’s doing.

The preferential balancing-point is going to be different for everyone, but I found that Julia is the sweet spot for me. I got introduced to programming way back via a good-old copy of K&R C. Eventually I picked up some C++, which was cool but definitely didn’t feel as simple. Then came Python, which early on felt like magic because of how much more productive I could be, but I missed the low-level feeling of control.

When I discovered Julia, I think what really connected with me was the feeling that I could still leverage some abstraction like I was accustomed to with Python, but it gave me back a lot of the feeling of low-level control I was missing. It also helped a lot that it seemed very natural to write scientific compute code in; in my opinion, Fortran always seemed awkward, Matlab felt like a bodged-up calculator syntax pretending to implement OO/lambda’s/etc, Python+Numpy were decent but still felt like scientific code was an after-thought vs a ground-up intent.

1 Like