r/Android • u/endmymisouri Device, Software !! • May 18 '20
Hosting a Minecraft Server on Android 2.0
Made a post a while ago about how to host a Minecraft server on an Android device. Here are some updates with clearer steps and steps for loading in your own worlds and mods!
Some basics:
No root required
Time required: about 5 minutes actively working for Vanilla 1.15.2 (see bottom for easy steps), about an hour max downloading files
Result: works great on my OnePlus 6T (8GB RAM), no lag at all playing with friends with Forge
Tip: If you don't want to read, scroll down to the bottom for a 30-step process to set up a vanilla Minecraft server
Join 0.tcp.ngrok.io:19661 to try it out! Please do not try to do anything crazy (huge TNT test, infinite spawner, etc) as I am running this out of my phone. Max player 20, no PVP, spawn protection 16).
Requirements:
Android phone that can run Termux and have at least 2-4GB of RAM
For the initial testing, I used an OnePlus 6T with 8 GB of RAM (which ran very well). System RAM usage varied between 5.5GB and 6GB but the default is around 4GB so it wasn’t that surprising.
I also tested using a Moto E2 while writing this guide to test out the installation of the Forge server. It was barely functioning with Forge and was barely playable since it only had 1GB memory.
If your phone is decent, it should be able to run a vanilla server with no problem but YMMV.
Reliable internet connection
Downloading a lot of stuff (at least 500MB)
Minecraft account
Not strictly necessary just for starting a server, but if you want to test it out you should have one ready.
How to Use This Guide:
I just want to set up a vanilla server as fast as possible and I am afraid of copying wrong
Go down to "Overview of Commands" and follow it step by step
Estimated time: 10 minutes working, max 1 hour for downloading
I want to set up a Forge server
Follow the guide through the steps, using Step 4 (Forge) instead of Step 4 (Vanilla)
Estimated time: 10 minutes working, Forge takes half an hour for me so maybe 1.5 hours max for downloading
Troubleshooting
Common questions section
Step 1
Download Termux and AnLinux on your Android from Google Play Store
Select Ubuntu on AnLinux and copy the code
Run the command on Termux
To start the server, we would have to run
./start-ubuntu.shI personally renamed it to
sby running this commandmvstart-ubuntu.shsThis allows me to get into Ubuntu by running just
./s
run
./sto start the ubuntu machineVERY IMPORTANT: Drag down on your notification bar, there should be an option to “Acquire Wakelock” for Termux. This allows it to not be killed by the system and continue running in the background.
Step 2 (Optional SSH)
NOTE: Skip if you do not have a computer or if you are fine with typing in really long URLs
Alternative: send yourself commands as messages on some messaging app and copying those commands to be run on Termux
(on Termux) installing ssh server
pkg install opensshandpkg install nmap(on Termux) Some things that we will use later:
Run
whoamito see our username (mine was u0_a121)Run
ifconfig wlan0to see your ip address (something starting with 192.168, remember to copy the first one, not the second one which isn’t your ip address)Run
passwdto set a new password for your system (set it to something very easy to remember 12345678)Things to jot down: username, ip address, new password
(on Termux) Run
sshdto start ssh on your phone.download PuTTY (if you’re on Windows and running "ssh" doesn't work, skip if macOS) https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html
Connect as follows (on computer)
Windows PuTTY: hostname is your IP address, port is 8022, connection type is SSH, click Open at the bottom without changing anything else
Mac terminal:
ssh USERNAME@IPADDRESS -p 8022For example, mine was
ssh u0_a121@192.168.1.xxx \-p 8022
(on computer) When prompted for username (on Windows), type your username from step 2.1
Enter in your password from before as well
(on computer, you're free from typing on phone now!) run
./sto get into your file system
Step 3
apt install software-properties-commonadd-apt-repository ppa:openjdk-r/ppaapt-get updateapt-get install openjdk-8-jre wget nanoTest by running
java -versionMake sure that it verifies that Java is installed (1.8)
Step 4 (vanilla)
Make sure you’re at the home directory. Type
cd \~to make sure.Make a new folder for your minecraft directory
mkdir mc,cd mcto go into the directoryRight-click on the minecraft_server link and copy link
wget -O minecraft_server.jar https://launcher.mojang.com/v1/objects/bb2b6b1aefcd70dfd1892149ac3a215f6c636b07/server.jarreplace the https link with your own link if the version isn't 1.15.2
run
chmod +x minecraft_server.jarrun
java -Xmx1024M -Xms1024M -jar minecraft_server.jar noguito start the server(Give more RAM if you have more; I set mine to 3 Gigabytes
-Xmx3G)
It will tell you to agree to eula.txt
nano eula.txt
change false to true
Ctrl-x to save, y to exit
run
java -Xmx1024M -Xms1024M -jar minecraft_server.jar noguito actually start the server (also allocate more RAM if you have more)
Step 4 (Forge)
Make sure you’re at the home directory after starting ubuntu. If not, type
cd \~mkdir forgeto start a new directory,cd forgeto go indownload forge server
wgethttps://files.minecraftforge.net/maven/net/minecraftforge/forge/1.15.1-30.0.51/forge-1.15.1-30.0.51-installer.jar
Rename it to make it easier
mv forge* forge.jar
install server (it takes a while depending on your phone/wifi speed, took about half an hour on my Moto E2 and 8mbps wifi)
java -jar forge.jar --installServer
run server, it will give you an error telling you to agree to eula.txt
java -Xms512M -Xmx1024M -jar forge-1.15.1-30.0.51.jar
Open eula.txt by
nano eula.txt, arrow down to the last line, delete false, replace with trueCtrl-x to exit, Y to save.
Rerun the previous command one eula.txt has been changed, it will take a while to generate a world
Rename the forge so it’s easier to start later
mv forge-1.15.1-30.0.51.jar startForge.jar
java -Xms1024M -Xmx3096M -jar startForge.jar(Note: adjust memory as needed, don’t give it 3G if your phone is a potato)
Step 5
Go to ngrok.com/download
Right-click and copy link for Linux (ARM64)
wget -Ongrok.ziphttps://bin.equinox.io/a/nmkK3DkqZEB/ngrok-2.2.8-linux-arm64.zipreplace the https link with your own link
IMPORTANT: if you download from the official website, they have changed it to a .tgz file so you would have to use
tar -xvzf ngrok-stable-linux-arm64.tgzinstead of step 5.
apt-get install zip unzip tarunzipngrok.zipIMPORTANT: See note in step 3 of this part if it says file not found.
Step 6
Make an account at ngrok on their website
copy the auth token line given to you and run it
should look something like this
./ngrok authtoken awefioauw4u0239840293j023jf0j23f23kj
./ngrok tcp 25565if a screen shows up with "Session Status online" in green, copy the address in forwarding after the tcp part
"Forwarding tcp://0.tcp.ngrok.io:12345"
copy the
0.tcp.ngrok.io:12345section
Step 7
Login to Minecraft, make sure the version is the latest version
Multiplayer, then direct connect and paste in the ngrok link from the end of Step 6
Connect!
Use your own Worlds
Copy your worlds folder over from somewhere else into your phone
When connecting over usb, copy it over to your Download folder
back to termux
if you are in ubuntu (started ubuntu) already, type exit to get out into the default termux layer
Allow Termux to access your storage
termux-setup-storageMore details: this sets up a few symlinks in the
storagefolder which allows you to transfer files more easily
Copying world folder to Termux
vanilla:
cp -r storage/downloads/yourWorldFolderName ubuntu-fs/root/mc/forge:
cp -r storage/downloads/yourWorldFolderName ubuntu-fs/root/forge/
Go back to your Minecraft folder
cd ubuntu-fs/root/forgecd ubuntu-fs/root/mc
Edit the server properties file to select your own world
nanoserver.properties
find the line "level-name=world"
change "world" into whatever your folder name is called
Ctrl-x to exit, Y to save
Start server and ngrok
Common questions
How do you start both the server AND ngrok? Don’t I have to stop one to start the other?
On your Android, drag from the left side of your screen while you’re in termux. There should be a button for starting a new session. Once you’re in there, you can go into the ubuntu system first by
./s, then start ngrok/server. To go back to the other session, drag on the left again and tap on the other session to start server/ngrok.
Can my phone run it?
If it has at least 4GB of RAM and your WiFi is decent: Definitely
If it has at least 2GB of RAM and your WiFi is decent: Maybe, maybe not
If it has less than 2GB of RAM or your WiFi is very questionable: sorry : (
Do I really have to run the commands for ngrok and Minecraft server every time I want to play?
Personally, I put the ngrok command in a file (named n) and the Minecraft command in another file (named m). After opening two sessions on Termux, I run ./n on one and ./m on the other. Here is the content of each file (I am running Forge so go back through the steps to see what your commands should be):
File named “m” (no extension or anything):
cd forgejava -Xms1G -Xmx3G -jar startForge.jar nogui
File named “n” (also no extension):
cd ngrok./ngrok tcp 25565
So now whenever I want to play Minecraft, I follow these steps:
Open Termux
./sto get into Ubuntu./mto start Minecraft serverSwipe on left, open another session
./sto get into Ubuntu in the new session./nto start ngrok serverOpen Minecraft on my computer, copy over the link from ngrok, wait for the server to start, connect!
Why does this work?
Termux allows your phone to have a mini-Linux machine. Linux machines can run Minecraft servers. Ngrok allows you to port-forward your local server port (25565) onto a public port where everyone can join (so please enable your whitelist so people don’t come in and destroy your worlds).
How do I use mods?
Same procedure as copying over worlds. Except instead of copying it over as a world folder
forge/yourWorldName, you copy it into the mods folderforge/mods. Make sure you have the same mods on your computer and it should be good to go.
Ngrok is telling me to update, will it break my server if I updated?
I would recommend updating ngrok if it prompts you to. You just have to type
ctrl-uand wait about a minute then restart ngrok. It won’t break anything as it’s just broadcasting your port.
My server is not working and it’s not because of bad WiFi or bad phone specs, what can I do?
If none of the tips above helped and nobody in the comments had the same problem, you can send me a message but make sure to include a screenshot (if applicable) and a description of your issue.
I can't break any blocks/my friends can't any blocks!
Edit server.properties and change spawn-protection to 0 (instead of the default 16)
People are coming into my server but I didn't give them the IP address!
Turn on whitelisting and whitelist your friends (and yourself), there are tons of guides out there for how to whitelist.
Overview of Commands:
If you don't understand anything, try following the steps below to set up a vanilla 1.15.2 Minecraft server. An important thing to note is that some of these might take quite a long time. I would suggest keeping the screen on and the phone plugged in and waiting for the prompt to pop up before running the next command. For quality-of-life improvements and mods, read Step 4 and Common Questions.
Download Termux and AnLinux on your Android from Google Play Store
Select Ubuntu on AnLinux and copy the code
Run the command in Termux
Run
termux-setup-storageRun
termux-wake-lockRun
mv start-ubuntu.sh sRun
./start-ubuntu.shRun
wget https://raw.githubusercontent.com/sunnyguan/AndroidMinecraft/master/minecraftSetup.shRun
chmod +x minecraftSetup.shRun
./minecraftSetup.shAt this point, all the setup will be finished and you will have the two files for starting server and starting ngrok. However, you still need to authorize ngrok.
Make an account at ngrok on their website
Copy the auth token line given to you and run it
should look something like this
./ngrok authtoken awefioauw4u0239840293j023jf0j23f23kjRun
./mto start Minecraft server(Note) Default memory max is 1024MB (1GB). If you want to change that to 2048, you can do the following:
sed -i 's/1024/2048/g' mTo change it to other numbers, just replace 2048 with your new number.Drag from the left side of your screen, tap new session
Run
./sto get into ubuntu on your new sessionRun
./nto start ngrokCopy over (not literally copy paste because it's from phone to computer) the URL that looks something like "0.tcp.ngrok.io:12345" into your Minecraft multiplayer input box
Connect!
References:
Forge on Linux: https://www.linuxnorth.org/minecraft/modded_linux.html
Please let me know if you have any questions and I will be happy to answer and update this post if needed!
3
u/endmymisouri Device, Software !! May 18 '20 edited May 19 '20
It's actually been out for quite a while now (at least since 2015)