How to Fix the "WSL Redis Encountered System Has Not Been Booted with systemd as Init System (PID 1). Can't Operate" Error?

To fix the “WSL Redis Encountered System Has Not Been Booted with systemd as Init System (PID 1). Can’t Operate” error, we can look at ways to run Redis without systemd. Windows Subsystem for Linux (WSL) does not support systemd. We can run Redis directly in the terminal or use Docker. Docker gives us a better way to manage Redis instances.

In this article, we will look at different solutions to fix the WSL Redis systemd error. We will talk about what causes the problem. We will also show how to install Redis without systemd on WSL. Then we will explain how to use Redis with Docker. We will show how to run Redis as a background process too. Lastly, we will share how to change Redis settings to work with WSL. We will also answer some common questions about these solutions.

  • How to Fix WSL Redis Encountered System Has Not Been Booted with systemd as Init System PID 1 Can’t Operate Error
  • What is the Cause of the WSL Redis Systemd Error
  • How to Install Redis Without systemd on WSL
  • How to Use Redis with Docker on Windows Subsystem for Linux
  • How to Run Redis as a Background Process on WSL
  • How to Modify Redis Configuration for WSL Compatibility
  • Frequently Asked Questions

What is the Cause of the WSL Redis Systemd Error

The error “WSL Redis Encountered System Has Not Been Booted with systemd as Init System (PID 1). Can’t Operate” happens because Windows Subsystem for Linux (WSL) versions 1 and 2 do not use systemd as their init system. Redis needs systemd to manage services. This includes starting and stopping the Redis server.

Here are some key causes:

  • WSL Limitation: WSL does not support systemd by default. This means that any service needing systemd, like Redis in some setups, will not start.
  • Service Management: Redis wants to be managed as a service. Without systemd, Redis cannot start or be managed as it should be.
  • Configuration Dependency: Some Redis settings expect systemd to be there. This leads to problems when we run Redis in WSL.

To fix this problem, we can look for other ways. One option is to run Redis in Docker. Another option is to set up Redis to work without systemd. For more information on how to install and use Redis, we can check how to install Redis.

How to Install Redis Without systemd on WSL

To install Redis on Windows Subsystem for Linux (WSL) without using systemd, we can follow these steps.

  1. Open WSL Terminal: Let us start the WSL terminal. For example, we can use Ubuntu.

  2. Update Package List: We need to update the package list first.

    sudo apt update
  3. Install Redis: Now, we can install Redis.

    sudo apt install redis-server
  4. Configure Redis to Run Without systemd: Next, we should edit the Redis configuration file. This helps it run well.

    sudo nano /etc/redis/redis.conf

    We need to find this line:

    supervised no

    Then, we change it to:

    supervised systemd

    After that, we save and exit the editor.

  5. Start Redis Manually: Instead of using systemctl, we start Redis directly like this:

    redis-server /etc/redis/redis.conf
  6. Verify Redis is Running: Now, we can check if Redis is running. Open another terminal or tab and run:

    redis-cli ping

    We should see this response:

    PONG

This way, we can run Redis without using systemd. Systemd is not available in WSL. If we want to learn more about Redis and how to install it, we can check how to install Redis.

How to Use Redis with Docker on Windows Subsystem for Linux

We can use Redis with Docker on Windows Subsystem for Linux (WSL) by following these steps.

  1. Install Docker Desktop:
    First, we need to make sure we have Docker Desktop on our Windows computer. We can download it from the Docker website. Don’t forget to enable the WSL integration when we install it.

  2. Check Docker Installation:
    Next, we open our WSL terminal. We should check if Docker is running by typing this command:

    docker --version
  3. Pull the Redis Image:
    Now, we need to get the official Redis image from Docker Hub. We can do this by running:

    docker pull redis
  4. Run Redis Container:
    We can start a new Redis container with this command. It runs Redis in detached mode:

    docker run --name my-redis -d -p 6379:6379 redis

    This command connects port 6379 of the Redis container to port 6379 on our host.

  5. Verify Redis is Running:
    To check if the Redis container is running, we can use:

    docker ps

    We should see our Redis container in the list.

  6. Access Redis CLI:
    We can interact with Redis by accessing the Redis CLI through the running container. We do this by running:

    docker exec -it my-redis redis-cli

    Now, we can run Redis commands like:

    set key "value"
    get key
  7. Persisting Data:
    If we want to keep the Redis data, we can mount a volume to our Redis container. We can run Redis with a data volume using this command:

    docker run --name my-redis -d -p 6379:6379 -v redis-data:/data redis
  8. Stopping and Removing the Container:
    To stop the Redis container, we can use:

    docker stop my-redis

    And to remove the container, we run:

    docker rm my-redis

By following these steps, we can use Redis with Docker on WSL. This helps us use Redis features in our development environment. For more details about configuring Redis or using it with programming languages, we can check out how to install Redis.

How to Run Redis as a Background Process on WSL

We can run Redis as a background process on Windows Subsystem for Linux (WSL). We use a command to start Redis in detached mode. This way, Redis keeps running even if we close the terminal.

  1. Start Redis Server in Background
    We can start the Redis server in the background by using the --daemonize yes option. Here is how we do it:

    redis-server --daemonize yes
  2. Verify Redis is Running
    To check if Redis is running, we can use this command:

    redis-cli ping

    If Redis is running, it will reply with PONG.

  3. Configure Redis for Persistent Background Operation
    We need to make sure that our Redis configuration file (redis.conf) has the daemonize option set to yes. We can edit the configuration file like this:

    sudo nano /etc/redis/redis.conf

    We look for the line daemonize no and change it to:

    daemonize yes

    We save and exit the editor.

  4. Start Redis with the Configuration File
    After we change the configuration, we can start Redis using the configuration file:

    redis-server /etc/redis/redis.conf
  5. Stop Redis from Running in the Background
    If we want to stop Redis, we can run this command:

    redis-cli shutdown

By doing these steps, we can run Redis as a background process on WSL. It will work without needing an active terminal session. For more details on how to install Redis on WSL, check this tutorial.

How to Modify Redis Configuration for WSL Compatibility

We need to configure Redis for best performance on Windows Subsystem for Linux (WSL). This means we have to change some settings in the Redis configuration file.

  1. Find the Configuration File: The usual name for the Redis configuration file is redis.conf. We can create or change it in our home directory or in the place where we installed Redis.

    nano ~/redis.conf
  2. Change These Settings:

    • Set the Daemonize Parameter: WSL does not work with daemonization. So we need to set this to no.

      daemonize no
    • Adjust the Supervised Parameter: WSL does not use systemd. So we also set this to no.

      supervised no
    • Bind to Localhost: We should make sure Redis binds to localhost. This helps to avoid connection problems.

      bind 127.0.0.1
    • Change the Port if Needed: The default Redis port is 6379. We can change this if we want.

      port 6379
  3. Saving Data: If we want Redis to keep our data, we need to make sure the save lines are not commented out.

    save 900 1
    save 300 10
    save 60 10000
  4. Start Redis: After we change the configuration file, we can start Redis with this command:

    redis-server ~/redis.conf
  5. More Settings Options: Depending on what we need, we can also change other options like maxmemory, appendonly, and loglevel.

By doing these changes, we make sure Redis works well in the WSL environment without needing systemd. For more details about Redis, please check the installation guide.

Frequently Asked Questions

1. What does the “WSL Redis Encountered System Has Not Been Booted with systemd as Init System (PID 1). Can’t Operate” error mean?

This error means that the Windows Subsystem for Linux (WSL) is not using systemd as its init system. We need systemd to manage services like Redis. Redis usually needs systemd to work. So, this error shows up when we try to start Redis in WSL. For more help, check our guide on fixing this problem.

2. Can I run Redis on WSL without using systemd?

Yes, we can run Redis on WSL without systemd. One easy way is to run Redis as a background process from the command line. We can start Redis with the command redis-server &. This makes it run in the background. This way is good for people who do not have systemd in their WSL setup.

3. How can I use Docker to run Redis on WSL?

We can run Redis using Docker on WSL easily. First, we need to make sure we have Docker installed and running on our Windows computer. Then, we can pull the Redis image with this command:

docker pull redis

After we get the image, we start a Redis container with:

docker run --name my-redis -d redis

Now we can use Redis without any systemd problems.

4. What are the configuration changes needed for Redis to work on WSL?

To make Redis work well on WSL, we might need to change the redis.conf file. We need to set daemonize to no and make sure the bind address is 127.0.0.1. These changes help Redis run directly in the terminal without systemd. For more detailed settings, check our article on installing Redis.

5. Is there a way to run Redis as a service on WSL?

WSL does not support services directly because it does not have systemd. But we can make it act like a service by using scripts to start Redis when we open WSL. We can create a script that runs the Redis server in the background whenever we open our WSL terminal. This way, we can have service-like behavior without full systemd support.

These FAQs help us understand the “WSL Redis Encountered System Has Not Been Booted with systemd as Init System (PID 1). Can’t Operate” error. They also show us other ways to run Redis in WSL. For more about Redis and what it can do, check our resources on Redis data types and using Redis with Docker.